alias
alias

Reputation: 155

How to get checkbox in grid widgetcolumn from cellclick?

My checkbox column:

{
   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
      }
   }
}

How get checkbox in cellclick grid event for set value proggramatically? In cellclick me need change value of checkbox(cbox.setValue(!cbox.getValue()); or the same).

Upvotes: 2

Views: 1948

Answers (1)

Sergey Novikov
Sergey Novikov

Reputation: 4196

Not sure if it is best solution, but you can do something like this:

{
    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');
    }
}

and

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

Upvotes: 2

Related Questions