How to use a filter on a NatTable without headers (neither column nor row) [message #1755233] |
Wed, 01 March 2017 11:16 |
ADeveloper Repoleved Messages: 4 Registered: February 2017 |
Junior Member |
|
|
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 15:11 |
Dirk Fauth Messages: 2902 Registered: July 2012 |
Senior Member |
|
|
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 15:16] Report message to a moderator
|
|
|
Re: How to use a filter on a NatTable without headers (neither column nor row) [message #1755344 is a reply to message #1755246] |
Thu, 02 March 2017 13:39 |
ADeveloper Repoleved Messages: 4 Registered: February 2017 |
Junior Member |
|
|
There are a couple of things that are not clear to me.
1) parameter columnPropertyAccessor:
I'm just going to filter by col 0, in that column users are shown (Person) then I build it like this:
String[] propertyNames = {"person"};
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<String, String>();
propertyToLabelMap.put("person", "Person");
2) What to do with the selectionLayer? In other examples (with GridLayer) is used in ColumnHeaderLayer...
[Updated on: Thu, 02 March 2017 13:41] Report message to a moderator
|
|
|
|
Re: How to use a filter on a NatTable without headers (neither column nor row) [message #1755357 is a reply to message #1755345] |
Thu, 02 March 2017 15:41 |
ADeveloper Repoleved Messages: 4 Registered: February 2017 |
Junior Member |
|
|
Hi Dirk.
Quote:And do I understand correctly that you only want to provide a filter for the first column in the first row?
Yes, I want to put FilterRowTextCellEditor in the first row to filter only on the first column
Quote:Not for the other columns?
Not for others columns.
Quote:I mean you are using the FreezeLayer so I assume you have multiple columns.
Yes, my table is an activity calendar and the first column is the users I want to filter and I use FreezeeLayer to emulate the headers (first column is the row header and first two rows are the column header).
If I use a GridLayer (with ColumnHeaderLayer and RowHeaderLayer) instead of the CompositeLayer with FreezeeLayer can I filter only on the first column (row header)?
And put the FilterRowTextCellEditor in the corner region?
Thank you very much anyway.
[Updated on: Thu, 02 March 2017 15:43] Report message to a moderator
|
|
|
|
Re: How to use a filter on a NatTable without headers (neither column nor row) [message #1755372 is a reply to message #1755361] |
Thu, 02 March 2017 16:56 |
ADeveloper Repoleved Messages: 4 Registered: February 2017 |
Junior Member |
|
|
I'm sorry, I have not explained correctly, I illustrate the problem with an image.
In the cell with the text "write user filter" you have to enter the user name that you want to filter.
Example: If you type User 1 then only the User 11 and User 12 rows will be displayed.
Quote:Alternatively you could implement a filter from the outside. If you use the FilterList you can set filters via some text field that is not included in the NatTable and set the filter to the FilterList this way. Then no filter row integration in NatTable is needed.
I think it's a good alternative
-
Attachment: Example.png
(Size: 6.40KB, Downloaded 281 times)
[Updated on: Thu, 02 March 2017 17:00] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03560 seconds