Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » How to use a filter on a NatTable without headers (neither column nor row)
How to use a filter on a NatTable without headers (neither column nor row) [message #1755233] Wed, 01 March 2017 11:16 Go to next message
ADeveloper Repoleved is currently offline ADeveloper RepolevedFriend
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 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
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 Go to previous messageGo to next message
ADeveloper Repoleved is currently offline ADeveloper RepolevedFriend
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 #1755345 is a reply to message #1755344] Thu, 02 March 2017 13:48 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Sorry I don't get your point.

Why are you asking about the ColumnHeaderLayer if you don't have a ColumnHeaderLayer?

And what is the question about the columnPropertyAccessor? I thought you already have a working NatTable setup. So you should have everything in place.

And do I understand correctly that you only want to provide a filter for the first column in the first row? Not for the other columns? I mean you are using the FreezeLayer so I assume you have multiple columns. If you only want to add a filter cell in one column my solution given above is not working. That would be also such a special case that is not trivial to solve, so I can't answer that on this forum.
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 Go to previous messageGo to next message
ADeveloper Repoleved is currently offline ADeveloper RepolevedFriend
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 #1755361 is a reply to message #1755357] Thu, 02 March 2017 16:07 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
It doesn't make much sense what you are trying to achieve. I mean you can also add the FilterRow like I explained and make only the cell in the first column in the filter row editable. But what would users think about the other cells in the filter row that actually do nothing?

Well it is your implementation, so you can do what you want. Actually you only need to configure the editable rules in a way that only the first column is editable in the filter row.

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.
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 Go to previous message
ADeveloper Repoleved is currently offline ADeveloper RepolevedFriend
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

Previous Topic:Row height based on position, Instead of Index
Next Topic:Using Filtering and Sorting with TreeList.Format ( Tree )
Goto Forum:
  


Current Time: Fri Apr 19 18:53:17 GMT 2024

Powered by FUDForum. Page generated in 0.03560 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top