如何以编程方式设置列过滤器? [英] How can I programmatically set column filters?

查看:64
本文介绍了如何以编程方式设置列过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Ext.js 5 Web应用程序.我有一个Ext.grid.Panel,我有

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.

谢谢!

更新:感谢DrakeES向我指出了正确的方向.我需要做的是添加此代码...

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. 检索列过滤器.为了简化操作,将itemId分配给列config:
  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. 如果菜单不存在,请启动菜单;
  2. 检索相关的复选框菜单项,并将其选中.

代码:

var filter = grid.down('#status').filter;
if (!filter.menu) {
    filter.createMenu();
}
filter.menu
    .down('menuitem[value="Ready"]')
    .setChecked(true);

完整示例: https://fiddle.sencha.com/#fiddle/pn6

这篇关于如何以编程方式设置列过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆