How to apply for a search in the GWT table?

I use GWT 2.3.I, which I use the GWT cellular network table. Below is the code of the table of my cells:

public class FormGrid extends SuperGrid { List<Form> formList; @Override public void setColumns(CellTable table) { TextColumn<Form> nameColumn = new TextColumn<Form>() { @Override public String getValue(Form object) { return object.getName(); } }; table.addColumn(nameColumn, "Name"); } @Override public void setData() { if (formList != null && formList.size() > 0) { AsyncDataProvider<Form> provider = new AsyncDataProvider<Form>() { @Override protected void onRangeChanged(HasData<Form> display) { int start = display.getVisibleRange().getStart(); int end = start + display.getVisibleRange().getLength(); end = end >= formList.size() ? formList.size() : end; List<Form> sub = formList.subList(start, end); updateRowData(start, sub); } }; provider.addDataDisplay(getTable()); provider.updateRowCount(formList.size(), true); } } public List<Form> getFormList() { return formList; } public void setFormList(List<Form> formList) { this.formList = formList; } 

}

In this column of my set and given data, the super superclass stream super will be called. This cell table is working fine. Now I want to put an object of type filter (e.g. search) in this cell table. It should be similar: there is a textbox above the cell table and what has ever been written in this text field should launch a similar query to the entire form name for this text field value.

for example, I have 1000 shapes in a grid. Now, if the user writes the “application” in some filter text field above the table of cells, the entire form that has the “application” there will be filtered out, and the grid will have only those forms

This is the first case:

Another case is that I only process one column in the grid name. I have two more properties in the form (description, tag). But I'm not drawing them. Now for the filter, if the user writes the "application" in the filter field, then he should make a request to all three (name, description and tag) and should return if the "application" matches any of the three.

I do not get how to apply a filter in a cell table. Please help me. Thanks in advance.

+8
gwt gxt smartgwt
source share
2 answers

You can find the implementation in expenses .

Below is a brief description of the steps.

1.) Create a text box and SearchButton.
2.) add clickHandler in SearchButton (you can also add KeyUpHandler in the text box)

 searchButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { search(); } }); 

3.) In the search function, find searchString and save it.

 private void search() { searchString = searchBox.getText(); setData(); } 

4.) modify your setdata () function to take into account the searchString parameter

 @Override public void setData() { if (formList != null && formList.size() > 0) { AsyncDataProvider<Form> provider = new AsyncDataProvider<Form>() { @Override protected void onRangeChanged(HasData<Form> display) { int start = display.getVisibleRange().getStart(); int end = start + display.getVisibleRange().getLength(); //new function if searchString is specified take into account List<Form> sub = getSubList(start,end); end = end >= sub.size() ? sub.size() : end; updateRowData(sub.subList(start, end);, sub); } }; provider.addDataDisplay(getTable()); provider.updateRowCount(formList.size(), true); } } private List<Form> getSubList(int start, int end) { List<Form> filtered_list = null; if (searchString != null) { filtered_list= new ArrayList<Form>(); for (Form form : formList) { if (form.getName().equals(searchString) || form.getTag().equals(searchString) || form.getDescription().equals(searchString)) filtered_list.add(form); } } else filtered_list = formList; return filtered_list; } 
+4
source share

may offer another solution that can be used quite easily several times. The idea is to create a custom provider for your cell table. GWT File Filtering

The video in this post shows this in action.

Here is part of the custom list data provider code that you need to implement.

  @Override protected void updateRowData(HasData display, int start, List values) { if (!hasFilter() || filter == null) { // we don't need to filter, so call base class super.updateRowData(display, start, values); } else { int end = start + values.size(); Range range = display.getVisibleRange(); int curStart = range.getStart(); int curLength = range.getLength(); int curEnd = curStart + curLength; if (start == curStart || (curStart < end && curEnd > start)) { int realStart = curStart < start ? start : curStart; int realEnd = curEnd > end ? end : curEnd; int realLength = realEnd - realStart; List<t> resulted = new ArrayList<t>(realLength); for (int i = realStart - start; i < realStart - start + realLength; i++) { if (filter.isValid((T) values.get(i), getFilter())) { resulted.add((T) values.get(i)); } } display.setRowData(realStart, resulted); display.setRowCount(resulted.size()); } } } 
+2
source share

All Articles