How to use a filter on a NatTable without headers (neither column nor row) [message #1755233] |
Wed, 01 March 2017 06:16  |
Eclipse User |
|
|
|
Hi all.
I need to put a filter on a nattable, but the table does not have the column header nor the row header and all the examples I've seen use a GridLayer (or CompositeLayer) with at least one rowHeader.
I use a CompositeLayer as the following code and I have to put the FilterRowTextCellEditor (or the Excel filter, it is not clear to me yet) in cell 0, 0 to filter over the 0 column.
any ideas?
(...)
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
final CompositeLayer compositeLayer = new CompositeLayer(1, 1);
compositeLayer.setChildLayer(GridRegion.BODY, compositeFreezeLayer, 0, 0);
final NatTable natTable = new NatTable(parent, compositeLayer, false);
(...)
Thanks in advance
|
|
|
Re: How to use a filter on a NatTable without headers (neither column nor row) [message #1755246 is a reply to message #1755233] |
Wed, 01 March 2017 10:11   |
Eclipse User |
|
|
|
Actually you need to add the FilterRowDataLayer as top layer in your CompositeLayer.
First you need to wrap your data list in a GlazedLists FilterList.
List<Person> data = PersonService.getPersons(10);
EventList<Person> eventList = GlazedLists.eventList(data);
FilterList<Person> filterList = new FilterList<>(eventList);
Then you need to create your body layer stack with the GlazedListsEventLayer on top of the DataLayer.
IDataProvider bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, filterList);
SelectionLayer selectionLayer = new SelectionLayer(eventLayer);
...
And then create your CompositeLayer with adding the FilterRowDataLayer and the necessary configurations for editing.
ConfigRegistry configRegistry = new ConfigRegistry();
IFilterStrategy<Person> filterStrategy = new DefaultGlazedListsFilterStrategy<>(
filterList,
columnPropertyAccessor,
configRegistry);
FilterRowDataLayer<Person> filterRowDataLayer = new FilterRowDataLayer<>(filterStrategy,
viewportLayer, bodyDataProvider, configRegistry);
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.FILTER_ROW, filterRowDataLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
compositeLayer.addConfiguration(new DefaultEditConfiguration());
compositeLayer.addConfiguration(new DefaultEditBindings());
NatTable natTable = new NatTable(parent, compositeLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.configure();
The parameter names in FilterRowDataLayer are a bit misleading, but it works that way. We should probably sometimes think about renaming them.
[Updated on: Wed, 01 March 2017 10:16] by Moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.18539 seconds