Ext.js5的表格的排序扩展(7)
2015-12-18 14:33
573 查看
/** * This example shows how to sort a grid by more than a single field. The store is initially * sorted by Rating DESC then by Salary ASC, as indicated in the headers. The `multiColumnSort` * config allows clicking on a header to either add that field as the primary sorter, or * if already sorted, it flips direction and moves that field to be the primary sort key. * 在排序方式上做的扩展,初始化的时候按照Rating DESC,然后按照 Salary ASC。没理解到这么做有啥意义,不分析了20151218。回头觉得这样有意义了再看。 */ Ext.define('KitchenSink.view.grid.MultipleSorting', { extend: 'Ext.grid.Panel', xtype: 'multi-sort-grid', bbar: { items: [{ xtype: 'component', itemId: 'order' }] }, columns: [{ text: 'Name', flex: 1 , dataIndex: 'name' }, { text: 'Rating', width: 125, dataIndex: 'rating' }, { text: 'Salary', width: 125, dataIndex: 'salary', align: 'right',//这里可以设置表格内容的对齐方式 formatter: 'usMoney' }], height: 350, width : 600, multiColumnSort: true,//允许点击标题时将他作为分类器 initComponent: function () { var me = this; me.store = new Ext.data.Store({ fields: [ {name: 'rating', type: 'int'}, {name: 'salary', type: 'float'}, {name: 'name'} ], //请求数据 proxy: { type: 'memory', data: this.createFakeData(25), reader: { type: 'array' } }, autoLoad: true, sorters: [{ property: 'rating', direction: 'DESC' }, 'salary'], listeners: { sort: me.updateSortTitle, scope: me } }); me.callParent(); me.updateSortTitle(); }, updateSortTitle: function() { var sortDetail = []; this.store.getSorters().each(function(sorter) { sortDetail.push(sorter.getProperty() + ' ' + sorter.getDirection()); }); this.down('#order').update('Sorted By: ' + sortDetail.join(', ')); }, /** * Returns an array of fake data * @param {Number} count The number of fake rows to create data for * @return {Array} The fake record data, suitable for usage with an ArrayReader */ createFakeData: function (count) { var firstNames = ['Don', 'Phil', 'Nige', 'Evan', 'Aaron', 'Abe', 'Jamie', 'Doug', 'Craig', 'Mike'], lastNames = ['Griffin', 'Guerrant', 'White', 'Trimboli', 'Conran', 'Elias', 'Avins', 'Hendricks', 'Gering', 'Estes'], ratings = [1, 2, 3, 4, 5], salaries = [85000, 100000, 175000, 162000, 300000]; var data = []; for (var i = 0; i < (count || 25); i++) { var ratingId = Math.floor(Math.random() * ratings.length), salaryId = Math.floor(Math.random() * salaries.length), firstNameId = Math.floor(Math.random() * firstNames.length), lastNameId = Math.floor(Math.random() * lastNames.length), rating = ratings[ratingId], salary = salaries[salaryId], name = Ext.String.format("{0} {1}", firstNames[firstNameId], lastNames[lastNameId]); data.push([rating, salary, name]); } return data; } });
相关文章推荐
- javascript级联菜单的操作
- leetcode(58)Length of Last Word js代码实现
- Ext.js5带子标题的标题的表格(6)
- JavaScript setTimeout使用闭包功能实现定时打印数值
- JS如何获取上传标签的文件路径和文件名?
- javascript JSON.stringify 语法实例讲解
- JavaScript验证手机号是否正确(正则表达式)
- Javascript生成GUID
- javascript closure
- How do JavaScript closures work?
- javascript 中arguments.callee 调用自身
- js数组引用传递
- js 操作数组
- js的闭包
- js实现双击后网页自己主动跑-------Day55
- 第五章_JSTL
- javascript深入理解js闭包
- videojs 动态加载视频
- JSON.parse()的正确用法
- Javascript Charts