javascript - ExtJs getTotalCount() not returning the number of records in the store -


when invoke function controller loads data in store in following manner,

var store= new ext.getstore('mystore'); store.load();      

the response header shows following json data returned,

{"usrdata":[{"name":"john",              "roll":"5",              "address":"abcd"            }] } 

but problem when write

console.log(store.gettotalcount()); 

it shows '0' (zero) on console.

can please me identify why not showing actual count of number of records in store.

i feel might because store has not finished loading when function invoked (may not correct).

following code of store:

ext.define('myapp.store.mystore', {     extend: 'ext.data.store',      model: 'myapp.model.mymodel',      timeout : 60000,     proxy: {         type: 'ajax',         api: {             create: 'php/insert.php',              read: 'php/read.php',             update: 'php/update.php',             destroy: 'php/delete.php',         },         reader: {             type: 'json',             root: 'usrdata',             successproperty: 'success'         },         writer: {             type: 'json',             writeallfields: true,             encode: true,             root: 'usrdata'         }     },     autoload: true, }); 

you need tiny change in store definition

ext.define('myapp.store.mystore', {      extend: 'ext.data.store',       model: 'myapp.model.mymodel',        timeout : 60000,      proxy: {          type: 'ajax',          api: {              create: 'php/insert.php',               read: 'php/read.php',              update: 'php/update.php',              destroy: 'php/delete.php',          },          reader: {              type: 'json',              root: 'usrdata',              totalproperty : '<the_node_of_json_response_which_holds_the_count>'              successproperty: 'success'          },          writer: {              type: 'json',              writeallfields: true,              encode: true,              root: 'usrdata'          }      },      autoload: true,  });

ps - service needs return count. gettotalcount() not return how many records store contains, returns number totalproperty of reader object holds.

so if service returning data -

{      "total": 122,      "offset": 0,      "users": [          {              "id": "ed-spencer-1",              "value": 1,              "user": {                  "id": 1,                  "name": "ed spencer",                  "email": "ed@sencha.com"              }          }      ]  }

your reader object -

 reader: {                  type: 'json',                  root: 'usrdata',                  totalproperty : 'total'                  successproperty: 'success'              },


Comments