根据值,Extjs checkcolumn禁用某些行

Nam*_*ess 16 checkbox datagrid extjs extjs4

我有一个带有checkcolumn的网格.例如,dataIndex是'checked'.

我想禁用或隐藏某些行的复选框,其中另一个值"can_be_checked"例如为false/empty.

Renderer已经在checkcolumn中定义,搞乱它会破坏复选框的生成.

我该怎么做?

Ani*_*tos 25

您可以隐藏渲染器内的复选框,例如:

column.renderer = function(val, m, rec) {
    if (rec.get('can_be_checked') == 'FALSE'))
        return '';
    else
        return (new Ext.ux.CheckColumn()).renderer(val);
};
Run Code Online (Sandbox Code Playgroud)


Aci*_*ier 12

我正在寻找一个解决方案,并遇到了这个问题,但在任何地方都没有可行的解决方案来显示禁用复选框而不是其他答案所涵盖的NO复选框.这有点介入,但这就是我所做的(4.1.0):

  1. 我发现使用的extjs\examples\ux\css\CheckHeader.css文件Ext.ux.CheckColumn没有禁用类,因此我不得不将其修改为更像ext-all.css中包含的标准复选框样式(其中确实包括一个禁用的复选框类).

  2. 我必须扩展Ext.ux.CheckColumn以防止被禁用的复选框触发事件.

  3. 最后,我必须根据我的逻辑提供我自己的渲染器来应用禁用的类.

代码如下.

修改后的CheckHeader.css:

.x-grid-cell-checkcolumn .x-grid-cell-inner {
    padding-top: 4px;
    padding-bottom: 2px;
    line-height: 14px;
}
.x-grid-with-row-lines .x-grid-cell-checkcolumn .x-grid-cell-inner {
    padding-top: 3px;
}

.x-grid-checkheader {
    width: 13px;
    height: 13px;
    background-image: url('../images/checkbox.gif');
    background-repeat: no-repeat;
    background-color: transparent;
    overflow: hidden;
    padding: 0;
    border: 0;
    display: block;
    margin: auto;
}

.x-grid-checkheader-checked {
    background-position: 0 -13px;
}

.x-grid-checkheader-disabled {
    background-position: -39px 0;
}

.x-grid-checkheader-checked-disabled {
    background-position: -39px -13px;
}

.x-grid-checkheader-editor .x-form-cb-wrap {
    text-align: center;
}
Run Code Online (Sandbox Code Playgroud)

上面的背景图像网址指向此图像,该图像通常附带extjs 4.1.0 at:extjs\resources\themes\images\default\form\checkbox.gif.

ExtJS的\资源\主题\影像\ DEFAULT \表格\ checkbox.gif

扩展的Ext.ux.CheckColumn类,以便不会从禁用的checkcolumns触发事件:

Ext.define('MyApp.ux.DisableCheckColumn', {
    extend: 'Ext.ux.CheckColumn',
    alias: 'widget.disablecheckcolumn',

    /**
     * Only process events for checkboxes that do not have a "disabled" class
     */
    processEvent: function(type, view, cell, recordIndex, cellIndex, e) {
        var enabled = Ext.query('[class*=disabled]', cell).length == 0,
            me = this;

        if (enabled) {
            me.callParent(arguments);
        }
    },

});
Run Code Online (Sandbox Code Playgroud)

使用自定义渲染器实现根据我自己的逻辑应用禁用的类:

column = {
    xtype: 'disablecheckcolumn',
    text: myText,
    dataIndex: myDataIndex,
    renderer: function(value, meta, record) {
        var cssPrefix = Ext.baseCSSPrefix,
            cls = [cssPrefix + 'grid-checkheader'],
            disabled = // logic to disable checkbox e.g.: !can_be_checked

        if (value && disabled) {
            cls.push(cssPrefix + 'grid-checkheader-checked-disabled');
        } else if (value) {
            cls.push(cssPrefix + 'grid-checkheader-checked');
        } else if (disabled) {
            cls.push(cssPrefix + 'grid-checkheader-disabled');
        }

        return '<div class="' + cls.join(' ') + '">&#160;</div>';

    }
};
Run Code Online (Sandbox Code Playgroud)