Hi. I need to get access to the contents of a Grid (GridPro) as a List with the filtering/sorting of the Grid preserved.
The Grid is using a ListDataProvider for the contents so I tried using the ListDataProvider.fetch() method, however it is not obivious how to get the query parameter based on the current Grid status?
/** Provide an Ordered (Filtered/Sorted) list of the items in the Grid respecting the current sort/filter */
@SuppressWarnings({"unchecked", "rawtypes"})
public List<SessionInteraction> getCurrentGridContents() {
Object filter = null;
try {
Method method = DataCommunicator.class.getDeclaredMethod("getFilter");
method.setAccessible(true);
filter = method.invoke(grid.getDataCommunicator());
} catch (Exception ignored) {}
var query = new Query(0, grid.getDataProvider().size(new Query(filter)), grid.getDataCommunicator().getBackEndSorting(),
grid.getDataCommunicator().getInMemorySorting(), null);
Stream<SessionInteraction> dataStream = grid.getDataProvider().fetch(query);
return dataStream.collect(Collectors.toList());
}
/** Provide an Ordered (Filtered/Sorted) list of the items in the Grid respecting the current sort/filter */
@SuppressWarnings({"unchecked"})
public List<SessionInteraction> getCurrentGridContents() {
ListDataProvider<SessionInteraction> dataProvider = (ListDataProvider<SessionInteraction>) grid.getDataProvider();
int totalSize = dataProvider.getItems().size();
DataCommunicator<SessionInteraction> dataCommunicator = grid.getDataCommunicator();
Stream<SessionInteraction> stream = dataProvider.fetch(new Query<>(
0,
totalSize,
dataCommunicator.getBackEndSorting(),
dataCommunicator.getInMemorySorting(),
dataProvider.getFilter()));
return stream.collect(Collectors.toList());
}
Which is pretty much what I had from the Exporter code but w/o the need to use reflection to get the DataCommunicator. It still looks to me like the DataProvider should provide this directly with something like.
it resembles your code yes, the idea is to fetch a list from the dataprovider using a query. But besides not needing reflection, you had some other mistakes, like grid.getDataProvider().size(new Query(filter)), and using null as filter.
It still looks to me like the DataProvider should provide this directly with something like public List<T> getCurrentItems();