Home » Eclipse Projects » NatTable » Quick Search feature in the Excel like filters(Implementing a quick search textbox feature to filter the combobox filter list)
Quick Search feature in the Excel like filters [message #1709021] |
Wed, 23 September 2015 11:16 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
I'm trying to implement a quick search feature in the excel like filters for my nattable. Something like the Excel filters have (See upload).
Can I somehow combine the text filter (FilterRowHeaderComposite) with the combobox filter (ComboBoxFilterRowHeaderComposite) as to have a cell where I can type some text and filter the combobox filter list?
Is there any simple way to do this without using the Painter to create a new UI component that runs like the excel like filter only with the added textbox to filter the comboboxes?
If this doesn't work, can I somehow have two header rows, one for Comboboxes and one for Text filter?
Any ideas?
[Updated on: Wed, 23 September 2015 11:17] Report message to a moderator
|
|
| |
Re: Quick Search feature in the Excel like filters [message #1709104 is a reply to message #1709033] |
Thu, 24 September 2015 06:14 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
How exactly should I configure it?
I presume you're talking about the ComboBoxFilterRowHeaderComposite class, since I see there is where the combobox is created.
Only that the class, besides the get and set methods, has a doCommand method which does the actual filtering after i check a box, and the rest of the UI component is done in its constructors. Normally I'd extend the class and overwrite the method responsible for a certain behaviour, to do something, only slightly different. However, here, I can't exactly see how I'd do that since it's not possible to overwrite class constructors.
A method to filter by text the combobox filters I could do, I'd just have to add a textbox (or make the cell editable), transmit the parameter from the textbox and then search by regular expression in the filterList and create a new filterList to load in the ComboBoxFilterRowHeaderComposite. But I don't know how I could correctly integrate this with the current NatTable.
Any advice? I apologize, but I'm not exactly proficient with NatTable or Eclipse plugins, I'm just trying to learn.
[Updated on: Thu, 24 September 2015 06:53] Report message to a moderator
|
|
| |
Re: Quick Search feature in the Excel like filters [message #1709786 is a reply to message #1709109] |
Thu, 01 October 2015 06:49 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
Ok, I managed to do something like a quick search like this: The cell where you press for the combobox context menu is now editable. A listener is there and collects a string which then passes it to an algorithm as a regular expression to search for names in the filter list so that the only visible combobox filters are the ones whose name contains the word you write in the header cell. Kinda buggy for the moment but it works.
Now I have a question: Normally in order to refresh the combobox filters I have to press Enter and then get the context menu out again in order to see the changed combobox list. How can I do that on the fly, as the combobox filter list to dynamically change depending on what I type in the cell? I think there is a command that does the refresh when I click somewhere else on the table or I press the Enter key. Could you point me out to that command or mechanism that does the context menu refresh?
Also, say I want to have this feature only on my first column and the rest to be usual non editable combobox filters. How can I set just one cell/column to have this filter implementation?
[Updated on: Thu, 01 October 2015 11:55] Report message to a moderator
|
|
| | | |
Re: Quick Search feature in the Excel like filters [message #1709929 is a reply to message #1709860] |
Fri, 02 October 2015 05:45 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
Let me do a quick recap of what I did
First of all I have a non editable nattable, to which I want to add a filter header layer with the ComboBox Filter, except that when I type into the header row cells, the ComboBox filters in the dropdown menu to automatically filter depending on what I type. Say initially I have 10 ComboBoxes that I can select/check in the dropdown menu, 5 of them start with "A". I write "A" and the dropdown menu now shows only the five comboboxes that start with "A". I delete "A" and again all 10 comboboxes show up again in the dropdown menu. No filtering in the actual table, only in the dropdown menu that shows Comboboxes to select/check.
Now for what I've done:
1) created a ComboBoxFilterRowHeaderComposite with constructor parameter useDefaultConfiguration == false and specified a custom configuration. Created my very own custom ComboBoxFilterRowConfiguration1.
2) created a customFilterRowComboBoxCellEditor1 (from which I removed the SWT.READ_ONLY as to make it editable) and also added a listener in the createEditorControl method which notices if I write something in the header row cell and collects what I write in a string variable.
3) created a custom ComboBoxCellEditor1 which is identical to the original ComboBoxCellEditor but I changed canonicalValues and the fillcombo method to protected. Also made my customFilterRowComboBoxCellEditor1 extend this class.
4) overwrited the fillCombo method from ComboBoxCellEditor1 to add to the dropdown menu the elements that correspond to the word I write in the editable cell:
@Override
public void fillCombo() {
List<String> displayValues = new ArrayList<String>();
List<?> values;
if (this.comboBoxDataProvider != null) {
values = this.comboBoxDataProvider.getValues(getColumnIndex(),
getRowIndex());
} else {
values = this.canonicalValues;
}
for (Object canonicalValue : values) {
if (canonicalValue.toString().contains(textValue)) // textValue is the string collected in the listener
displayValues.add((String) this.displayConverter
.canonicalToDisplayValue(this.layerCell,
this.configRegistry, canonicalValue));
}
this.combo.setItems(displayValues.toArray(ArrayUtil.STRING_TYPE_ARRAY));
}
I think this could have been done directly in the listener with combo.setItems(filteredListOfComboBoxFilters), but I had hoped using fillCombo would replace the dropdown menu content with the new one, instead it just adds to it indefinitely.
So here comes my problem. How do I remove Items from the dropdown menu. I get it, with setItems() method I can add to it but I can find no method that removes Items from it or that empties the dropdown menu, as to only introduce the list I want to see.
I need something like combo.removeItems(List), combo.empty(), combo.disposeItems() to get rid of the Items that were originally in the dropdown menu, at creation.
[Updated on: Fri, 02 October 2015 06:15] Report message to a moderator
|
|
| | | | | | | | | | |
Re: Quick Search feature in the Excel like filters [message #1711136 is a reply to message #1710690] |
Tue, 13 October 2015 11:43 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
Regarding the configuring filter options on columns I have been encountering some problems.
I tried two ways to create my Filter Row.
1) The first one is a Regular filter row and try to apply my custom Combobox on the first column, all rest remaining normal filters.
DefaultGlazedListsFilterStrategy<FTLVariableEvolution> filterStrategy = new DefaultGlazedListsFilterStrategy<FTLVariableEvolution>(
filterList, autoFilterMatcherEditor, columnPropertyAccessor,
configRegistry);
FilterRowHeaderComposite<FTLVariableEvolution> filterRowHeaderLayer = new FilterRowHeaderComposite<FTLVariableEvolution>(
filterStrategy, columnHeaderLayerStack,
columnHeaderDataProvider, configRegistry);
FilterRowComboBoxDataProvider2<FTLVariableEvolution> comboBoxDataProvider = new FilterRowComboBoxDataProvider2<FTLVariableEvolution>(
glazedListsEventLayer, sortedList, columnPropertyAccessor);
FilterRowComboBoxCellEditor2 cellEditor = new FilterRowComboBoxCellEditor2(
comboBoxDataProvider, 10);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR, cellEditor,
DisplayMode.NORMAL,
FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + 0);
This causes my Custom ComboBox Filter to glitch out.
The other way I tried is creating a ComboBox Filter Row and specifying in the configuration on which columns I want to put each filter
ComboBoxFilterRowHeaderComposite<FTLVariableEvolution> filterRowHeaderLayer3 = new ComboBoxFilterRowHeaderComposite<FTLVariableEvolution>(
filterList, origComboBoxDataProvider, columnPropertyAccessor,
columnHeaderLayer, columnHeaderDataProvider, configRegistry,
false);
ComboBoxFilterRowConfiguration2 configuration = new ComboBoxFilterRowConfiguration2(
comboBoxDataProvider);
filterRowHeaderLayer3.addConfiguration(configuration);
FilterRowComboBoxCellEditor comboBoxOrientationFilter = new FilterRowComboBoxCellEditor(
origComboBoxDataProvider, 10);
for (int i = 1; i <= 100; i++) {
if(i<=2)
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR,
comboBoxOrientationFilter, DisplayMode.NORMAL,
FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + i);
if(i>2)
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR,
new FilterRowTextCellEditor(), DisplayMode.NORMAL,
FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + i);
}
In my custom Configuration I have only the registerConfig or the first column:
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR, this.cellEditor,
DisplayMode.NORMAL,
FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + 0);
This instead, makes for only my first 3 columns being ok and the regular filters glitching out.
How can I add a regular FilterRowLayer on the rest of the columns? I can't seem to mix ComboBox filters and Regular filters on the same FilterRow, whenever I try to add one the other stops working or glitches out.
What I want to achieve basically is:
Table:
(FilterRow) CustomCombo | NormalCombo | NormalCombo | NormalTextFilter | NormalTextFilter | ... | NormalTextFilter
[Updated on: Tue, 13 October 2015 11:49] Report message to a moderator
|
|
| | | | | | |
Re: Quick Search feature in the Excel like filters [message #1711513 is a reply to message #1711471] |
Fri, 16 October 2015 14:26 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
Ah ,yes. I'll be out of town for the weekend, but I'll test it next week and if it would work it would be terrific.
Frankly I isolated the problem down to the ComboBoxDataProvider, which I assume scans the table and collects values from each column at startup. I noticed that if I use for example 2 data providers it takes 7 minutes, 3 -> 10 minutes etc.
The only thing to watch out for is that it doesn't affect the performance when expanding the combobox dropdown menu, since that could result in being more annoying because of the cumulated time. If it's down to a couple of milliseconds it would be ok, but if it lasts up to a couple of seconds and considering someone might check and uncheck comboboxes frequently that might be a bugger.
As you say, if the filter combo values would be initialized and cached (and stay there, as to not make this operation each and every time) when you click on the filter (to get the dropdown menu) for the first time for that specific row, I think this would work.
|
|
| | |
Re: Quick Search feature in the Excel like filters [message #1711840 is a reply to message #1711692] |
Tue, 20 October 2015 06:07 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
I tested it a bit and I must say it works quite well at improving performance. From 2 minutes and 7 second I've went down to 2 seconds.
I did notice some annoying things though:
1) When I open the ComboBox Dropdown menu for the first time, all filters are unselected. They should be all selected, like in the previous ComboBox Filter.
->This should be just inserting a selectAll() after fillCombo() when it first populates the dropdown menu with items
2) If I first filter a column and then I proceed to filter another column the second dropdown menu only populates with the items currently in the filtered table. And since the dropdown menu population happens only once it means that if I remove the filter from the first collumn, revealing all items on column 2, the dropdown of column 2 will still only show the items that were present when the table was first filtered (and when I first clicked on the column 2 dropdown).
Let me give you an example:
Column1 Column2
1 ----------- a
2 ----------- b
3 ----------- c
4 ----------- d
5 ----------- e
Say I first filter column1, checking the comboboxes of 1,2 and 5
the new table should look like this:
Column1 Column2
1 ----------- a
2 ----------- b
5 ----------- e
Now, if I click on the column2 dropdown it will naturally show a, b and e as combobox options to check.
But say I remove the filter on column1 and select all again:
Column1 Column2
1 ----------- a
2 ----------- b
3 ----------- c
4 ----------- d
5 ----------- e
Now if I click on the column2 dropdown it will still show me only a, b and e as options to check, despite b and c being present now.
I thought of 2 solutions here:
i) Either perform the operation each time we open the dropdown, which would reduce performance a lot when dealing with million row tables, but would work out well with smaller tables or tables with just lots of columns.
ii) Implement a new mechanism that notices if the table has been filtered and only does the final dropdown population if nothing is filtered.
|
|
| |
Re: Quick Search feature in the Excel like filters [message #1711854 is a reply to message #1711849] |
Tue, 20 October 2015 07:33 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
For the first issue, yes, I think it might be local. I didn't actually apply the patch, instead I took the classes you modified and inserted them into my project as Provisory<Name>, then I continued using, extending and overriding them instead of the original ones, so the integration might not have gone as smooth as I thought.
For the second one, yes, I use FilterList, though come to think of it, I could use SortedList instead.
|
|
| |
Re: Quick Search feature in the Excel like filters [message #1711879 is a reply to message #1711866] |
Tue, 20 October 2015 08:50 |
Cristi Andrei Messages: 21 Registered: August 2015 |
Junior Member |
|
|
Sorry, I wasn't paying enough attention, before. I actually create my ComboBoxFilterRowHeaderComposite with a ComboBoxDataProvider like this:
FilterRowComboBoxDataProvider<Things> comboBoxDataProvider = new FilterRowComboBoxDataProvider<Things>(
glazedListsEventLayer, sortedList, columnPropertyAccessor);
ComboBoxFilterRowHeaderComposite<Things> filterRowHeaderLayer = new ComboBoxFilterRowHeaderComposite<Things>(
filterList, comboBoxDataProvider, columnPropertyAccessor,
columnHeaderLayer, columnHeaderDataProvider, configRegistry,
false);
I also have a custom Configuration.
The baseCollection I give to the DataProvider is a SortedList.
The sorted list I create like this:
sortedList = new SortedList<Things>(filterList, null);
[Updated on: Tue, 20 October 2015 09:03] Report message to a moderator
|
|
| | | | | | | |
Goto Forum:
Current Time: Thu Sep 26 18:32:21 GMT 2024
Powered by FUDForum. Page generated in 0.07191 seconds
|