Skip to content

Commit

Permalink
fix #906 no scrollbar visible if setFixedBodyHeight too big
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jan 17, 2024
1 parent 9dd9fdc commit d76209d
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class LocalListScrollingDataSource<T> implements DataStore<T> {
private final List<T> original;
private List<T> filtered = new ArrayList<>();
private final int pageSize;
private int initialLoadedPages = 1;
private int pageIndex = 0;
private List<StoreDataChangeListener<T>> listeners = new ArrayList<>();
private SearchFilter<T> searchFilter;
Expand All @@ -59,6 +60,18 @@ public LocalListScrollingDataSource(int pageSize) {
this.pageSize = pageSize;
}

/**
* Creates a new instance of {@link LocalListScrollingDataSource} with the specified page size.
*
* @param pageSize The number of records to load per page.
* @param initialLoadedPages The number of pages to load in the initial load - page index 0 -.
*/
public LocalListScrollingDataSource(int pageSize, int initialLoadedPages) {
this.original = new ArrayList<>();
this.pageSize = pageSize;
this.initialLoadedPages = initialLoadedPages;
}

/**
* Creates a new instance of {@link LocalListScrollingDataSource} with the specified page size and
* initial data.
Expand All @@ -72,6 +85,21 @@ public LocalListScrollingDataSource(List<T> data, int pageSize) {
this.filtered.addAll(data);
}

/**
* Creates a new instance of {@link LocalListScrollingDataSource} with the specified page size and
* initial data.
*
* @param data The initial data to populate the data source.
* @param pageSize The number of records to load per page.
* @param initialLoadedPages The number of pages to load in the initial load - page index 0 -.
*/
public LocalListScrollingDataSource(List<T> data, int pageSize, int initialLoadedPages) {
this.original = data;
this.pageSize = pageSize;
this.initialLoadedPages = initialLoadedPages;
this.filtered.addAll(data);
}

/**
* Retrieves a copy of records stored in the data store.
*
Expand Down Expand Up @@ -162,7 +190,7 @@ public void load() {

private void fireUpdate(boolean append) {
int fromIndex = pageSize * pageIndex;
int toIndex = Math.min(fromIndex + pageSize, filtered.size());
int toIndex = Math.min(getToIndex(fromIndex), filtered.size());

listeners.forEach(
dataChangeListener ->
Expand All @@ -173,6 +201,15 @@ private void fireUpdate(boolean append) {
filtered.size())));
}

private int getToIndex(int fromIndex) {
if (pageIndex == 0 && initialLoadedPages > 1) {
int toIndex = fromIndex + (initialLoadedPages * pageSize);
pageIndex = initialLoadedPages - 1;
return toIndex;
}
return fromIndex + pageSize;
}

/**
* Handles various table-related events and delegates to specific event handling methods based on
* the event type.
Expand Down

0 comments on commit d76209d

Please sign in to comment.