-
18 Oct 2010 6:45 AM #1
Paging Grid with filters
Paging Grid with filters
Hello everyone!
I'm new in GXT and in posting in forums, so I hope I am writing in the right place. My problem is that I am trying to implement a paging grid that also use filters. To implement the paging grid, I am using this source code:
PagingModelMemoryProxy proxy =new PagingModelMemoryProxy(TestData.getCompanies());
final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
loader.setRemoteSort(true);
listStore = new ListStore<Company>(loader);
bottomToolBar = new PagingToolBar(10);
bottomToolBar.bind(loader);
loader.load(0, 10);
grid = new Grid<Company>(listStore, cm);
grid.getView().setForceFit(true);
grid.setStyleAttribute("borderTop", "none");
grid.setWidth("100");
grid.setAutoExpandColumn("comercialName");
grid.setBorders(false);
grid.setStripeRows(true);
grid.setColumnLines(true);
grid.setColumnReordering(true);
grid.setAutoHeight(true);
where "TestData.getCompanies()" gets the data that are displayed in the grid, and "cm" is the ColumnModel with the configuration for the columns. That is working fine. My problem is that I have a combo to filter the grid. After select a value in the combo, I want to reload the whole grid, and shows only the results filtered. But I want to filter the whole set of data, and not only the data which is in the current page you are looking at. I don't know if I am explaining my situation well... But I would like to update also the number of pages showed.
For example, I have 3000 companies, 1500 of them are from "Italy" and the others 1500 are from "Poland". My grid shows a total of 300 pages. If I am watching one of the pages that only shows companies from "Poland" and I filter "Italy", that page of the grid is empty of data, and the count of pages is still 300 when it would have to reload and only shows 150 pages with the companies that are from "Italy".
I would be very grateful if somebody has any idea. Thank you so much and sorry if my English or my explanation is not very good.
-
18 Oct 2010 6:47 AM #2
You will need to extend PagingModelMemoryProxy to support filtering. Your proxy should only return the data that matches the query and only a subset of this filtered data.
-
18 Oct 2010 7:01 AM #3
First of all, thank you so much for your fast answer. Could you tell me a little bit more in details how could I do that? Do I have to override some of the methods of PagingModelMemoryProxy class or define a new one? Thank you so much.
-
18 Oct 2010 7:02 AM #4
You need to override the load method and add this filtering support before it builds the sublist.
-
18 Oct 2010 7:42 AM #5
I was wondering how could I do that, and looking other threads in this forum.. but I still have no idea. Could you write some code of how to do it? Thank you so much for all your help.
-
18 Oct 2010 7:46 AM #6
I dont have any code for this. This is a simple algorithm.
Take the list of all your data and go over the list. Create a second list that only contains the items that match your query. Than in the second step you take this second list and create a sublist from it with the given size and given offset. Your load method should return this third list (the sublist of your filtered data)
-
18 Oct 2010 11:30 PM #7
Hi,
I have this method:
I suppose that I have to apply the filters in that section, but I don't know how, any idea ???? another problem is that in this method I don't have the filters, have I ?Code:@Override public void load(DataReader<PagingLoadResult<? extends ModelData>> reader, Object loadConfig, AsyncCallback<PagingLoadResult<? extends ModelData>> callback) { try { PagingLoadResult d = null; if (reader != null) { d = reader.read(loadConfig, data); } else { if (data instanceof List) { d = new BasePagingLoadResult(new ArrayList((List) data)); } else { PagingLoadResult r = (PagingLoadResult) data; d = new BasePagingLoadResult(new ArrayList(r.getData()), r.getOffset(), r.getTotalLength()); } } PagingLoadConfig config = (PagingLoadConfig) loadConfig; if (config.getSortInfo().getSortField() != null) { final String sortField = config.getSortInfo().getSortField(); if (sortField != null) { Collections.sort(d.getData(), config.getSortInfo().getSortDir().comparator(new Comparator<ModelData>() { public int compare(ModelData o1, ModelData o2) { Object v1 = (Object) o1.get(sortField); Object v2 = (Object) o2.get(sortField); if (comparator != null) { return comparator.compare(v1, v2); } else { return DefaultComparator.INSTANCE.compare(v1, v2); } } })); } } List<ModelData> sublist = new ArrayList<ModelData>(); int start = config.getOffset(); int limit = d.getData().size(); if (config.getLimit() > 0) { limit = Math.min(start + config.getLimit(), limit); } for (int i = config.getOffset(); i < limit; i++) { sublist.add((ModelData) d.getData().get(i)); } //here is where i have to apply the filters List<ModelData> sublist2 = new ArrayList<ModelData>(); for (ModelData modelData : sublist) { } //end callback.onSuccess(new BasePagingLoadResult<ModelData>(sublist, config.getOffset(), d.getData().size())); } catch (Exception e) { callback.onFailure(e); } }
Please help me, it's taking me a lot of time ??????
-
24 Oct 2010 4:26 AM #8
I am trying to override the "load" method but I have no idea how to do it. How can I build a list that only contains the items that match my filter???
List<Company> list = new ArrayList<Company>();
list.add(grid.getStore().applyFilters("null"));
???
I defined some of my filters using the StoreFilterField and anothers with StoreFilter, but the StoreFilter is defined inside the listener of a combobox..
any idea or help?? I would be really grateful, because it is very important for me to solve this problem..
Thanks in advance!
Similar Threads
-
after grid reconfigure grid filters (Ext.grid.GridFilters) does not work
By wwwjsx in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 2 Jul 2010, 11:07 PM -
Filters on a grid
By yegortitov in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 21 Jun 2010, 2:38 AM -
setvalue filters and paging
By EducatedFool in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 17 Nov 2008, 7:56 AM -
Get Grid Filters
By acontreras in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 3 Oct 2008, 4:55 AM -
Help with PlugIn (Grid Filters)
By businessman332211 in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 19 Jun 2008, 11:08 AM


Reply With Quote