PDA

View Full Version : Problem with GridFilters and GridCellRenderer



aminef
7 Dec 2010, 1:35 PM
Basically I want to use the GridFilters with a grid that has a rendered column ("Contact" column), and the data shown in this column is html text (String). When I use the StringFilter on this column, it never shows any result (the grid is empty). However if I use the same filter to another column ("ID" this one was not rendered, and also contains String data) it works perfectly.

So is there anything I should be aware of this GridFilters <-> GridCellRenderer combination?

Here's my code:

this is the ID clumn


ColumnConfig column = new ColumnConfig("ID", "ID", 80);
column.setRowHeader(true);
configs.add(column);

this is the CONTACT one

column = new ColumnConfig("Contact", "Contact Information", 130);
configs.add(column);
GridCellRenderer<PersInfo> cellRender = new GridCellRenderer<PersInfo>() {
@Override
public Object render(PersInfo model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<PersInfo> store, Grid<PersInfo> grid) {
String contactInfo = "";
contactInfo = model.getContactInfo();
return contactInfo;
}
};
column.setRenderer(cellRender);


and this is my grid filters


GridFilters filters = new GridFilters();
StringFilter contactFilter = new StringFilter("Contact");
StringFilter idFilter = new StringFilter("ID");
filters.addFilter(contactFilter);
filters.addFilter(idFilter);
filters.setLocal(true);
grid.addPlugin(filters);

Thanks for the help

sven
7 Dec 2010, 1:37 PM
Does your model actually contain anything under the configured dataindex "Contact"? The filtering will be done on the dataindex, not the value you actually rendered.

aminef
7 Dec 2010, 1:48 PM
I am sorry sven but I don't think I understood your question. You mean if my PersInfo model contain any data?
these are screenshots of the troubleshoots I am having:

Before : http://img143.imageshack.us/i/beforeb.jpg/
After ID Filter : http://img340.imageshack.us/i/afterid.jpg/
After Contact Filter: http://img823.imageshack.us/i/aftercontact.jpg/

sven
7 Dec 2010, 1:51 PM
No. You configured your columnconfig with a "Contact" dataindex. If you would not use a renderer, the grid would take the content it would fine in the "Contact" dataindex. The filter will also look under this dataindex and not on the valeu you actually rendered

aminef
7 Dec 2010, 1:54 PM
I see, but then how I make the filter go look into the value of the cell?

sven
7 Dec 2010, 1:59 PM
Nothing like this is implemented. Safe the value you actually render in a field in the model.

aminef
7 Dec 2010, 2:04 PM
The main issue is (as you've seen in the screenshots I posted earlier) there's a Highlight feature in my grids, and I can't do that in the model side (because I need to compare the searched item and the result from the server).
So from my understanding there's no other way to surround this (not even creating a custom filter?) unless trying to avoid the render and have a String variable instead?

Thanks a lot for your help

sven
7 Dec 2010, 2:06 PM
A custom filter will also work. You need to extend StringFitler and override getModelValue. Instead of looking at the model, get the value from the rendered cell.

aminef
7 Dec 2010, 2:08 PM
Thank you for your time! I really appreciate all this help.
I will do that and I will let you know!

Thank you sven!

aminef
7 Dec 2010, 3:10 PM
Thanks a lot sven,
I just created a new custom filter that extends Filter, and it has a lot of similarities with the StringFilter, but here's what I changed:


@Override
public boolean validateModel(ModelData model) {
if(model instanceof PersInfo){
String val = ((PersInfo)model).getContactInfo();
String v = getValue().toString();
if (v.length() == 0 && (val == null || val.length() == 0)) {
return true;
} else if (val == null) {
return false;
} else {
return val.toLowerCase().indexOf(v.toLowerCase()) > -1;
}
}else {
String val = getModelValue(model);
String v = getValue().toString();
if (v.length() == 0 && (val == null || val.length() == 0)) {
return true;
} else if (val == null) {
return false;
} else {
return val.toLowerCase().indexOf(v.toLowerCase()) > -1;
}
}

}


Of course this Filter now is acting like a StringFilter if the model is not my rendered model (wich is good to keep using the same)

sven
7 Dec 2010, 3:13 PM
Why do you override validateModel and not getModelValue? would be much easier.

aminef
7 Dec 2010, 7:36 PM
I didn't find getModelValue in StringFilter (I have gxt 2.2.0) but I thought that validateModel will work, and it did.
But if you think overriding getModelValue is better, I will work on it and change it.

Thank you again sven!

sven
8 Dec 2010, 2:00 AM
Ok, thought you are on the latest. Its in 2.2.1.