1 Ext.Loader.setConfig({enabled: true});
2 Ext.Loader.setPath('Ext.ux', '../ux');
6 'Ext.ux.grid.FiltersFeature',
10 Ext.onReady(function(){
14 // for this demo configure local and remote urls for demo purposes
16 local: 'grid-filter.json', // static data file
17 remote: 'grid-filter.php'
20 // configure whether filter query is encoded or not (initially)
23 // configure whether filtering is performed locally or remotely (initially)
26 var store = Ext.create('Ext.data.JsonStore', {
32 url: (local ? url.local : url.remote),
37 totalProperty: 'total'
52 { name: 'price', type: 'float' },
53 { name: 'date', type: 'date', dateFormat: 'Y-m-d' },
54 { name: 'visible', type: 'boolean' },
61 // encode and local configuration options defined previously for easier reuse
62 encode: encode, // json encode the filter query
63 local: local, // defaults to false (remote filtering)
80 options: ['small', 'medium', 'large', 'extra large'],
88 // use a factory method to reduce code while demonstrating
89 // that the GridFilter plugin may be configured with or without
90 // the filter types (the filters may be specified on the column model
91 var createHeaders = function (finish, start) {
96 // instead of specifying filter config just specify filterable=true
97 // to use store's field's type property (if type property not
98 // explicitly specified in store config it will be 'auto' which
99 // GridFilters will assume to be 'StringFilter'
101 //,filter: {type: 'numeric'}
103 dataIndex: 'company',
109 // specify disabled to disable the filter menu
116 //type: 'numeric' // specify type here or in store fields config
123 options: ['small', 'medium', 'large', 'extra large']
129 renderer: Ext.util.Format.dateRenderer('m/d/Y'),
131 //type: 'date' // specify type here or in store fields config
134 dataIndex: 'visible',
137 //type: 'boolean' // specify type here or in store fields config
141 return columns.slice(start || 0, finish);
144 var grid = Ext.create('Ext.grid.Panel', {
147 columns: createHeaders(4),
150 bbar: Ext.create('Ext.toolbar.Paging', {
155 // add some buttons to bottom toolbar just for demonstration purposes
156 grid.child('[dock=bottom]').add([
159 text: 'Encode: ' + (encode ? 'On' : 'Off'),
160 tooltip: 'Toggle Filter encoding on/off',
162 handler: function (button, state) {
163 var encode = (grid.filters.encode !== true);
164 var text = 'Encode: ' + (encode ? 'On' : 'Off');
165 grid.filters.encode = encode;
166 grid.filters.reload();
167 button.setText(text);
171 text: 'Local Filtering: ' + (local ? 'On' : 'Off'),
172 tooltip: 'Toggle Filtering between remote/local',
174 handler: function (button, state) {
175 var local = (grid.filters.local !== true),
176 text = 'Local Filtering: ' + (local ? 'On' : 'Off'),
177 newUrl = local ? url.local : url.remote,
178 store = grid.view.getStore();
180 // update the GridFilter setting
181 grid.filters.local = local;
182 // bind the store again so GridFilters is listening to appropriate store event
183 grid.filters.bindStore(store);
184 // update the url for the proxy
185 store.proxy.url = newUrl;
187 button.setText(text);
192 text: 'All Filter Data',
193 tooltip: 'Get Filter Data for Grid',
194 handler: function () {
195 var data = Ext.encode(grid.filters.getFilterData());
196 Ext.Msg.alert('All Filter Data',data);
199 text: 'Clear Filter Data',
200 handler: function () {
201 grid.filters.clearFilters();
205 handler: function () {
206 if (grid.headerCt.items.length < 6) {
207 grid.headerCt.add(createHeaders(6, 4));
215 var win = Ext.create('Ext.Window', {
216 title: 'Grid Filters Example',