Skip to content

Instantly share code, notes, and snippets.

@sohel-rana
Last active May 26, 2023 12:59
Show Gist options
  • Select an option

  • Save sohel-rana/7210342 to your computer and use it in GitHub Desktop.

Select an option

Save sohel-rana/7210342 to your computer and use it in GitHub Desktop.
Fill data dynamically in an ExtJS data store
//take an array to store the object that we will get from the ajax response
var records = [];
//create extjs store with empty data
var store = Ext.create('Ext.data.Store',{
fields : ['id','name'],
data: records,
paging : false
});
Ext.Ajax.request({
url : 'someurl.php',
params : {
max: 10
},
success : function(r){
//create a json object from the response string
var res = Ext.decode(r.responseText, true);
// if we have a valid json object, then process it
if(res !== null && typeof (res) !== 'undefined'){
// loop through the data
Ext.each(res.data, function(obj){
//add the records to the array
records.push({
id: obj.id,
name: obj.name
})
});
//update the store with the data that we got
store.loadData(records);
}
},
failure : function(r){
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment