extjs - 如何从 cellclick 获取网格小部件列中的复选框?

标签 extjs

我的复选框列:

{
   xtype: 'widgetcolumn',
   text: 'Selection',
   tdCls: 'actions',
   header: 'Selection',
   width: '5%',
   dataIndex: 'selection',
   widget: {
      xtype: 'checkbox',
      defaultBindProperty: 'disabled',
      listeners: {
         afterrender: function (chb) {
            var rec = chb.getWidgetRecord();
            chb.setValue(rec.get('selection'));
            chb.on('change', this.checkHandler);
            chb.setDisabled(rec.get('selection_disabled'));
         },
         scope: this
      }
   }
}

如何以编程方式获取 cellclick 网格事件中的复选框以设置值?在 cellclick 中,我需要更改复选框的值(cbox.setValue(!cbox.getValue()); 或相同)。

最佳答案

不确定这是否是最佳解决方案,但您可以执行以下操作:

{
    xtype: 'widgetcolumn',
    dataIndex: 'checked',
    flex: 1,
    text: 'Checked',

    widget: {
        xtype: 'checkbox'
    },
    onWidgetAttach: function(column, widget, record) {
        // Make sure your property / id pair is unique
        // You can use Ext.id() to generate id for your record and widget
        widget.widgetId = record.get('id');
    }
}

grid.on('cellclick', function(view, td, cellIndex, record) {
    var rowWidget = Ext.ComponentQuery.query('checkbox[widgetId=' + record.get('id') + ']')[0];
    if(rowWidget) {
        rowWidget.setValue(!rowWidget.getValue());
    }
});

Working fiddle

关于extjs - 如何从 cellclick 获取网格小部件列中的复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37275231/

相关文章:

javascript - ExtJS 5 - 将在网格中双击的单元格的值传递到新窗口

javascript - 使用鼠标滚轮在桌面上的 Sencha Touch 应用程序中滚动

javascript - 如何将商店注入(inject)面板的工具栏中?

javascript - 删除在网格 ExtJS 4 中选择特定行的能力

javascript - ExtJS 6 - 隐藏组件时停止事件委托(delegate)?

css - 在 ExtJs 按钮上添加图标

javascript - 当调用函数位于 html 属性中时,无法在 sencha touch 中获取父引用

javascript - Extjs 6 网格 + JSON

javascript - extjs 存储有时调用 create 而不是 update

javascript - 在浏览器中禁用 PDF 中嵌入的 JavaScript(XSS 攻击)