X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/3789b528d8dd8aad4558e38e22d775bcab1cbd36..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/guides/data/examples/sorting_grouping_filtering_store/app.js diff --git a/docs/guides/data/examples/sorting_grouping_filtering_store/app.js b/docs/guides/data/examples/sorting_grouping_filtering_store/app.js new file mode 100644 index 00000000..8a06d3dc --- /dev/null +++ b/docs/guides/data/examples/sorting_grouping_filtering_store/app.js @@ -0,0 +1,49 @@ +/** + * @example Sorting Grouping Filtering Store + * + * This example demonstrates {@link Ext.data.Store}'s sorting, grouping, and filtering capabilities. + * The data at url `data/users.json` is auto-loaded into the store. The data will be sorted first by name then id; + * it will be filtered to only include Users with the name 'Ed' and the data will be grouped by age. + * A global variable called "userStore" is created which is an instance of {@link Ext.data.Store}. + * Feel free to experiment with the "userStore" object on the console command line. + * `userStore.getGroups()` should return an array of groups. + */ +Ext.define('User', { + extend: 'Ext.data.Model', + fields: [ + {name: 'id', type: 'int'}, + {name: 'name', type: 'string'} + ] +}); + +var userStore; +Ext.require('Ext.data.Store'); +Ext.onReady(function() { + userStore = Ext.create('Ext.data.Store', { + model: 'User', + autoLoad: true, + + sorters: ['name', 'id'], // sort first by name, then by id + filters: { + // filter the data to only include users with the name 'Ed' + property: 'name', + value: 'Ed' + }, + groupers: { + // group the users by age in ascending order + property: 'age', + direction: 'ASC' + }, + + proxy: { + type: 'ajax', + url: 'data/users.json', + reader: { + type: 'json', + root: 'users', + successProperty: 'success' + } + } + }); +}); +