1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    6
    Vote Rating
    0
    lpr84 is on a distinguished road

      0  

    Default 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.

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Posts
    6
    Vote Rating
    0
    lpr84 is on a distinguished road

      0  

    Default


    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.

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You need to override the load method and add this filtering support before it builds the sublist.

  5. #5
    Sencha User
    Join Date
    Oct 2010
    Posts
    6
    Vote Rating
    0
    lpr84 is on a distinguished road

      0  

    Default


    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.

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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)

  7. #7
    Ext User
    Join Date
    Oct 2010
    Posts
    4
    Vote Rating
    0
    always is on a distinguished road

      0  

    Default


    Hi,

    I have this method:

    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);
    		}
    	}
    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 ?

    Please help me, it's taking me a lot of time ??????

  8. #8
    Sencha User
    Join Date
    Oct 2010
    Posts
    6
    Vote Rating
    0
    lpr84 is on a distinguished road

      0  

    Default


    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

  1. after grid reconfigure grid filters (Ext.grid.GridFilters) does not work
    By wwwjsx in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 2 Jul 2010, 11:07 PM
  2. Filters on a grid
    By yegortitov in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 21 Jun 2010, 2:38 AM
  3. setvalue filters and paging
    By EducatedFool in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 17 Nov 2008, 7:56 AM
  4. Get Grid Filters
    By acontreras in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 3 Oct 2008, 4:55 AM
  5. Help with PlugIn (Grid Filters)
    By businessman332211 in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 19 Jun 2008, 11:08 AM

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar