问题
I am working on a Ext.js 5 web applications. I have a Ext.grid.Panel and I have
selModel: {
type: 'spreadsheet'
},
Here is a screen shot of what I have now:
I would like to be able to set the filter on the 'Status' column to 'Ready'. I am not sure what I need to do.
Thanks!
UPDATE: Thanks to DrakeES for pointing me in the right direction. What I needed to do was add this code ...
1 /*global */
2 Ext.define("Requestor.view.main.RequestGrid", {
3 extend: 'Ext.grid.Panel', // Our base class. A grid panel.
...
42 // Here we define our grid columns based on our associated store and model.
43 columns: [
...
72 {
73 text: 'Status',
74 dataIndex: 'status',
75 itemId: 'status',
76 renderer: function(value, metaData) {
77 //RED
78 var filter = this.up('panel').down('#status').filter;
79 if (!filter.menu) {
80 filter.createMenu();
81 filter.menu
82 .down('menuitem[value="Ready"]')
83 .setChecked(true);
84 }
85 //RED
86 metaData.tdStyle = (value == 'Ready') ?
87 'color:green;font-weight: bold' :
88 'color:red;font-style: italic'
89 return(value)
90 },
91 filter: 'list',
92 flex: 1,
93 },
回答1:
- Retrieve the column filter. To make this easy, assign an
itemIdto the column config:
{
dataIndex: 'status',
text: 'Status',
itemId: 'status',
flex: 1,
filter: 'list'
}
- Initiate its menu if it does not exist yet;
- Retrieve the relevant checkbox menu item and make it checked.
Code:
var filter = grid.down('#status').filter;
if (!filter.menu) {
filter.createMenu();
}
filter.menu
.down('menuitem[value="Ready"]')
.setChecked(true);
Full example: https://fiddle.sencha.com/#fiddle/pn6
来源:https://stackoverflow.com/questions/31145262/how-can-i-programmatically-set-column-filters