[英]Antd Table Skip page: No Data
我稱基於偏移的分頁GraphQL端點 。 然后,數據將顯示在Antd表中 。
現在,單擊頁面底部時,所有操作均按預期方式進行:數據被獲取並附加到先前獲取的數據中。 但是,如果跳過頁面,則會觸發相同的例程。
例如
const previousData = [10, 11, 12]; // we are on page 1
// fetchMore && updateQuery, going to page 3 directly
const updatedData = [10, 11, 12, 30, 31, 32];
// Antd Table tries to access data on page 3, therefore at index behind item 32,
// as the page 3 items are in the place of page 2 items
這是某種預期的行為,到目前為止,我僅對第一頁和第三頁上的數據感興趣,而不對第二頁感興趣。 但是,Antd Table嘗試通過跳過前兩頁來顯示第三頁上的數據,同時假設每頁的頁面大小為3。 因此, pageSize * currentOffset = 3 * 1 = 6
它將嘗試訪問超出范圍的數據並顯示“無數據”。
有辦法繞過嗎? 我究竟做錯了什么?
哦。 我的。 神。 我自己找到了答案。
問題是我自己像這樣合並數據:
const mergedData = [...previousData, ...updatedData]
然后用於顯示。
顯然,這不是要走的路。 而是完全替換現有數據 。
所以現在我在Apollo fetchMore
正在做的是這樣的:
updateQuery: (previousResult, { fetchMoreResult }) => fetchMoreResult,
現在,一切都按預期進行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.