Filtering (Grid) exact data

Hi guys,

I have tried to implement filtering in Grid and really amaze how easy it is. But, It seems that Simple string filter only match items that start with or contain a specified string. Is it possible to have it exact match instead of just having to match that starts with or contain a specified string? can anyone share a solution for this?

There are couple of solutions I can think of

  1. Use Combobox and let the user select appropriate item.(I have documented it in my
    blog
    & Source code can be found
    here
    check for category field)
  2. This approach you can extend the SimpleStringFilter class with your custome class and then override the methods

[code]
@Override
public boolean passesFilter(Object itemId, Item item) {
final Property<?> p = item.getItemProperty(getPropertyId());
if (p == null) {
return false;
}
Object propertyValue = p.getValue();
if (propertyValue == null) {
return false;
}
//Write your logic here
final String value = isIgnoreCase() ? propertyValue.toString().toLowerCase() : propertyValue.toString();
if (!value.equals(filterString)) {
return false;
}

return true;
}
[/code]
NOTE:
I have
not
tested this method, just wrote on the fly in the editor and also you may be required to override the
equals()
either.

Hope this helps

Hi Krishna,

I’ll try the solution you suggested… Thank you