How can I programmatically set column filters?

我是研究僧i 提交于 2019-12-25 04:35:16

问题


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:


  1. Retrieve the column filter. To make this easy, assign an itemId to the column config:
{
    dataIndex: 'status',
    text: 'Status',
    itemId: 'status',
    flex: 1,
    filter: 'list'
}
  1. Initiate its menu if it does not exist yet;
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!