Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / 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 (file)
index 0000000..8a06d3d
--- /dev/null
@@ -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'
+            }
+        }
+    });
+});
+