Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 3.4 checkchange listener not working on Checkcolumn

The checkchange listener for my checkColumn is not working. Any ideas why not?

var checked = new Ext.grid.CheckColumn({
  header: 'Test',
  dataIndex: 'condition',
  renderer: function(v,p,record){
        var content = record.data['info'];      
        if(content == 'True'){
              p.css += ' x-grid3-check-col-td'; 
            return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
        }

  },    
  listeners:{
        checkchange: function(column, recordIndex, checked){
              alert("checked");
        }

  }

});
like image 676
pm13 Avatar asked Nov 13 '22 22:11

pm13


1 Answers

In Ext.ux.grid.CheckColumn, add this initialize method that register a checkchange event:

initComponent: function(){
  Ext.ux.grid.CheckColumn.superclass.initComponent.call(this);

  this.addEvents(
    'checkchange'
  );
},

Then in processEvent fire the event:

processEvent : function(name, e, grid, rowIndex, colIndex){
  if (name == 'mousedown') {
    var record = grid.store.getAt(rowIndex);
    record.set(this.dataIndex, !record.data[this.dataIndex]);

    // Fire checkchange event
    this.fireEvent('checkchange', this, record.data[this.dataIndex]);

    return false; // Cancel row selection.
  } else {
    return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
  }
},

The resulting CheckColumn component should look like this:

  Ext.ns('Ext.ux.grid');

  Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, {
    // private
    initComponent: function(){
      Ext.ux.grid.CheckColumn.superclass.initComponent.call(this);

      this.addEvents(
        'checkchange'
      );
    },

    processEvent : function(name, e, grid, rowIndex, colIndex){
      if (name == 'mousedown') {
        var record = grid.store.getAt(rowIndex);
        record.set(this.dataIndex, !record.data[this.dataIndex]);

        this.fireEvent('checkchange', this, record.data[this.dataIndex]);

        return false; // Cancel row selection.
      } else {
        return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
      }
    },

    renderer : function(v, p, record){
      p.css += ' x-grid3-check-col-td'; 
      return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
    },

    // Deprecate use as a plugin. Remove in 4.0
    init: Ext.emptyFn
  });

  // register ptype. Deprecate. Remove in 4.0
  Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);

  // backwards compat. Remove in 4.0
  Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;

  // register Column xtype
  Ext.grid.Column.types.checkcolumn = Ext.ux.grid.CheckColumn;
like image 102
sveilleux2 Avatar answered Dec 22 '22 07:12

sveilleux2