2014-09-22 49 views
0

尋找GWT DataGrid實現無限滾動的組件,但同時也確保丟棄屏幕上不再可見的結果:例如之前加載的結果未顯示了。GWT無限滾動,丟棄開始列表結果

這是爲了避免內存不足。 我一直在試圖在Google上找到這個,但目前爲止沒有運氣。 請注意:我可以帶一個JS庫並根據需要進行調整,但我認爲它不適用於GWT的DataGrid組件。

編輯:我特別感興趣的是無限滾動,它也放棄/釋放最不可見的結果(並在適當的時候加載它們)。

任何想法?

回答

3

事實上,showcase example有一個無限滾動CellList。 (你可以在那裏找到代碼)。
雖然這是用CellList完成的,但同樣的原理也應該適用於DataGrid
查看ShowMorePagerPanel.java文件。

更新:
ShowMorePagerPanel.java的onScroll功能將在底部添加了新的記錄。但是你可以很容易改變的行爲:

沿線(未測試韌)的東西:

HasRows display = getDisplay(); 
if (display == null) { 
    return; 
} 
boolean loadData = false; 
// If scrolling up, change newStart 
int oldScrollPos = lastScrollPos; 
lastScrollPos = scrollable.getVerticalScrollPosition(); 
// get the current visible Range 
Range currentRange = display.getVisibleRange(); 
if (oldScrollPos >= lastScrollPos) { 
    int newStart = Math.max(
     currentRange.getStart() - incrementSize,0); 
    loadData = true; 
} 

int maxScrollTop = scrollable.getWidget().getOffsetHeight() 
    - scrollable.getOffsetHeight(); 
if (lastScrollPos >= maxScrollTop) { 
    // We are near the end, so increase the page size. 
    int newPageSize = Math.min(
     display.getVisibleRange().getLength() + incrementSize, 
     display.getRowCount()); 
    loadData = true; 
} 
if (loadData) { 
    display.setVisibleRange(newStart, newPageSize); 
} 
+0

我知道的例子;我只是非常熱衷於拋棄不再可見的最頂層元素。編輯我的問題以更好地強調這一方面。 GWT Showcase的例子保存了整個元素列表。 – Andrei 2014-09-22 13:12:55

+0

我更新了答案(它是基於展示的)。不知道它是否行得通,因爲我只是在我的腦海裏做的 – 2014-09-22 13:31:04

+0

謝謝。但是請注意,這並不容易。滾動條不會看起來好像頂部有多個結果。因此,一個適當的實現可能需要考慮到這一點,並且可能會在頂部放置一個空白div或其他東西,大小與缺少的結果一樣大,或者類似的東西? – Andrei 2014-09-23 07:48:27