levivanzele
levivanzele

Reputation: 736

Multi column grid filter in SmartGWT

Consider a ListGrid with two columns: First Name, and Last Name.

What if I want to search across both columns at once? E.g. give me the records for which First Name or Last Name contain 'bob'. (Filled in using a single TextItem search field.)

It ought to return:

Ann, Bobbings
Bob, Doe
Chris, McBob

Is this possible with using just Criteria, or AdvancedCriteria? (E.g. grid.setCriteria(mySearchCriteria);)

Or would I have to customize the setCriteria in ListGrid, or the filterData in DataSource?

Upvotes: 1

Views: 1615

Answers (1)

Kimi
Kimi

Reputation: 6279

I have used this kind of implementation myself.

textItem.addChangedHandler(new ChangedHandler() {

  @Override
  public void onChanged(ChangedEvent event) {
    String input = (String) event.getValue();
    AdvancedCriteria criteria = new AdvancedCriteria(OperatorId.OR, new Criterion[]{
      // ICONTAINS = ignores case
      new Criterion("firstName", OperatorId.ICONTAINS, input),
      new Criterion("lastName", OperatorId.ICONTAINS, input)
    });

    listGrid.filterData(criteria);
  }
});

Upvotes: 1

Related Questions