Results 1 to 6 of 6

Thread: How to make store pageSize work with store.loadData for grid.Panels

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    253
    Vote Rating
    0
      0  

    Default How to make store pageSize work with store.loadData for grid.Panels

    I have a Store with pageWidth: 6
    a gridPanel, using this store, but when loading data, through grid.getStore().loadData(myarray);
    I have more than 6 lines, all showing in page 1/1

    additionally, trying to refresh the grid form the bbar, will cause a TypeError: Cannot read property 'length' of undefined

    exactly like is I do grid.getStore().load(), probably normal since I didn't use any proxy, I'm just loading the store manually on demand.

    Or do I have to use a store proxy reader, to query directly the store? but why it's not working in the first case




  2. #2
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
      0  

    Default

    Your data needs to be in the form of :

    Code:
    {
       message: 'Success',
       data: [
            {'Field1: 'Value1'},
            {'Field2:' Value'1}
       ],
       total: 107   <-- this is configured in the totalProperty of the stores reader
    }

    Without the total records property in the results, the paging cannot perform the calculations necessary and hense uses the number of records in the store.

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    253
    Vote Rating
    0
      0  

    Default

    I have changed
    Code:
    resultList.getStore().loadData(j);
    in
    Code:
    var total = j.length;
    resultList.getStore().load({message: 'Success', data: j, total: total});
    and have directly TypeError: Cannot read property 'length' of undefined

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
      0  

    Default

    Well, that's because your var j is undefined and has not length. Which is not indication of whether your method is working or not because you don't have any data. Also, you cannot do:

    Code:
    resultList.getStore().load({message: 'Success', data: j, total: total})
    Calling it this way implies remote data in which you cannot feed the data directly. You may be looking at trying to do soemthing like this...

    Code:
    resultList.getStore().loadData({message: 'Success', data: j, total: total});
    Although, I am not quite sure why you're paging at all if you have all the data already client side. Seems like remote paging is what you would want anyway.

  5. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    253
    Vote Rating
    0
      0  

    Default

    j is a valid json, it's length (it's an array) is valid also

    right, if I do this, my list will be empty

    I need to have a store that will applyData, using the data attribute from the json

    Code:
    var store = Ext.create('Ext.data.Store', {	      fields: ['publisherID', 'publisherName','city', 'text'], 
    	      sorters: ['publisherName'],
    	      groupField: 'city',
    	      pageSize: 6
    	  });
    how would I do that please?

  6. #6
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
      0  

    Default

    Have you configured your reader to use the 'data' property?

    Code:
    var store = Ext.create('Ext.data.Store', {          
            fields: ['publisherID', 'publisherName', 'city', 'text'],            
            sorters: ['publisherName'],           
            groupField: 'city',           
            pageSize: 6,
            proxy: {
                  type: 'ajax',
                  reader: {
                         type: 'json',
                         root: 'data' <------
                  }
            }       
    });

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •