Last active
May 26, 2023 12:59
-
-
Save sohel-rana/7210342 to your computer and use it in GitHub Desktop.
Fill data dynamically in an ExtJS data store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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