How to get checkbox in a grid panel?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vibhakhushi
    New Member
    • Mar 2010
    • 33

    How to get checkbox in a grid panel?

    Hello all,
    How to get a checkbox column in a grid panel? I want to have both normal columns and also a column of checkbox. Finally i read the record row wise not based on the checkbox which is selected. Can i have the grid panel with the above said options?
    I'm a newbie in ExtJS and using 2.3 for my project any tutorial to learn that is appreciable. Please help me with some example or tutorial :(
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    here is an example ... have a look at the code there ...

    kind regards

    Comment

    • vibhakhushi
      New Member
      • Mar 2010
      • 33

      #3
      Originally posted by gits
      here is an example ... have a look at the code there ...

      kind regards
      Hello gits... I saw your example. But when i tried it, i got this error...
      'Ext.grid.Check Column' [undefined] is not a constructor.

      I dont know how to resolve this error :(

      Comment

      • vibhakhushi
        New Member
        • Mar 2010
        • 33

        #4
        Originally posted by vibhakhushi
        Hello gits... I saw your example. But when i tried it, i got this error...
        'Ext.grid.Check Column' [undefined] is not a constructor.

        I dont know how to resolve this error :(
        Thank You gits... I resolved the error :) As it was a plugin i need to include this also in my code
        Code:
        Ext.grid.CheckColumn = function(config){
            Ext.apply(this, config);
            if(!this.id){
                this.id = Ext.id();
            }
            this.renderer = this.renderer.createDelegate(this);
        };
        
        Ext.grid.CheckColumn.prototype ={
            init : function(grid){
                this.grid = grid;
                this.grid.on('render', function(){
                    var view = this.grid.getView();
                    view.mainBody.on('mousedown', this.onMouseDown, this);
                }, this);
            },
        
            onMouseDown : function(e, t){
                if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
                    e.stopEvent();
                    var index = this.grid.getView().findRowIndex(t);
                    var record = this.grid.store.getAt(index);
                    record.set(this.dataIndex, !record.data[this.dataIndex]);
                }
            },
        
            renderer : function(v, p, record){
                p.css += ' x-grid3-check-col-td'; 
                return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
            }
        };
        thank you so much for your help :)
        Last edited by Dormilich; May 31 '10, 01:21 PM. Reason: Please use [code] tags when posting code

        Comment

        • meFab
          New Member
          • Nov 2012
          • 1

          #5
          What about Ext JS 4x

          Your proposed solution works great in Ext JS < 4. In 4 and above gridView looses the mainBody property... Has anyone found how to make this work in ExtJS 4 and above?

          Originally posted by vibhakhushi
          Thank You gits... I resolved the error :) As it was a plugin i need to include this also in my code
          Code:
          Ext.grid.CheckColumn = function(config){
              Ext.apply(this, config);
              if(!this.id){
                  this.id = Ext.id();
              }
              this.renderer = this.renderer.createDelegate(this);
          };
          
          Ext.grid.CheckColumn.prototype ={
              init : function(grid){
                  this.grid = grid;
                  this.grid.on('render', function(){
                      var view = this.grid.getView();
                      view.mainBody.on('mousedown', this.onMouseDown, this);
                  }, this);
              },
          
              onMouseDown : function(e, t){
                  if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
                      e.stopEvent();
                      var index = this.grid.getView().findRowIndex(t);
                      var record = this.grid.store.getAt(index);
                      record.set(this.dataIndex, !record.data[this.dataIndex]);
                  }
              },
          
              renderer : function(v, p, record){
                  p.css += ' x-grid3-check-col-td'; 
                  return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
              }
          };
          thank you so much for your help :)

          Comment

          Working...