0
votes

Here is the problem,

Server responds with several records in JSON, which number is greater than grid pageSize parameter specified in the Store. The total number is not returning by a server in this JSON with data. The number of such records is known and could be different (this number should be requested from the server in another request). The total number is needed for the pagingtoolbar.

How to tell the proxy reader this number from the view controller?

The only workable solution I found is to override the Ext.data.reader.Json reader with the following code:

Ext.define('MyApp.custom.AnotherReader',{
    extend: 'Ext.data.reader.Json',
    alias : 'reader.anotherReader',

    // разбираем ответ и записываем в store
    getResponseData : function(response) {
        var st = Ext.decode(response.responseText);
        st.total = 5;
        //console.log(st);
        return st;
    }
});

The problem is I cannot dynamically change this total parameter from the viewcontroller.

JSON 1:

[
  {
    "id":"1",
    "user_id":"11",
  },
  {
    "id":"2",
    "user_id":"12",
  },
  {
    "id":"3",
    "user_id":"13",
  },
  {
    "id":"4",
    "user_id":"14",
  },
  {
    "id":"5",
    "user_id":"15",
  }
]

JSON 2:

{
  "records_count": "5"
}
1
You don't have control over the server response?Yellen
You already have a hold of the array (or the JSON that holds your array) in your getResponse function. Why not do st.total = the_array_for_your_store.length?SelfSurgery
I've already mentioned, the number of rows is greater than grid pageSize parameter specified in the Store. That's why I have only a part of all records in the Store in the specific moment, dependent on limit and offset.fen1ksss
What do you want to happen if the number of rows > pageSize? Do you want to display all of the rows anyway? That will happen by default since pageSize doesn't affect anything except the parameters you send in your requests. Do you want to truncate your array? Then use array.spliceSelfSurgery
OK, this link will help you - stackoverflow.com/questions/14254321/…Yellen

1 Answers

1
votes

You can do this inside your controller -

    // some event handler/ or normal function inside your Controller that you'll call
    somFunction: function() {
        var me = this;
        var store = Ext.getStore(<storeId>); // you can even pass the store 
//instance as a parameter to this function
        var reader = store.getProxy().getReader();
        Ext.override(reader, {
            getResponseData : function(response) {
                var st = Ext.decode(response.responseText);
                st.total = me.getValueYouWant();
                return st;
            }
        });
    }