0

i am using checkboxmodel to select rows but i want to make some rows to be selection disabled based on some logic... here is my what i am trying but 'beforeselect' function doesn't even fires

    selModel: Ext.create('Ext.selection.CheckboxModel', {
      checkOnly: true,
    mode:'multi',
   listeners: {
     beforeselect:function(grid){
    var grid=Ext.getCmp('mylist');     
        var selectionModel=grid.getSelectionModel();
    var selectedRecords=selectionModel.getSelection();
    var myValue=selectedRecords[0].get('nowreceive');
    var myvalue1=selectedRecords[0].get('received');
    if(myValue>myvalue1)
    {return false;}
    else 
    return true;
        }}  }
    ),
Mir Gulam Sarwar
  • 2,588
  • 2
  • 25
  • 39

2 Answers2

3

beforecellmousedown event in the view config works for me.This is done in the viewconfig of the grid...

 viewConfig: {
 listeners: {
 beforecellmousedown: function(view, cell, cellIdx, record, row, rowIdx, eOpts){
               var myvalue=record.get('quantity_ordered');
               var myvalue1=record.get('quantity_received')
               if(myvalue==myvalue1)
               {
               return false;
               }
                   else {
                   return true;
                   }
            }
        }
    },
Mir Gulam Sarwar
  • 2,588
  • 2
  • 25
  • 39
0

How do you know the event is not firing? It should be, but my guess is that selectedRecords[0] is not defined and that crashes your execution, because getSelection() probably returns an empty array, before any selection has occurred.

What you should do is to use the second argument of beforeselect, which is the record that's going to be added to the selection.

So you can implement your listener in a much simpler way:

beforeselect: function (selModel, record) {
    if (record.get('nowreceive') > record.get('received')) {
        return false;
    }
}
rixo
  • 23,815
  • 4
  • 63
  • 68
  • it's true, beforeselect not firing,i tried what u say, i also tried simply this.. beforeselect: function (selModel, record) { alert('d'); ...but nothing from firebug/firefox – Mir Gulam Sarwar Jun 16 '13 at 14:37
  • What version of Ext are you using? You should try adding the listener directly to the grid panel, instead of the selection model. [`beforeselect` for grid](http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.panel.Table-event-beforeselect) is available since 4.0.0, while it is only available since 4.0.2 for [`CHeckboxModel`](http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.selection.RowModel-event-beforeselect)... – rixo Jun 16 '13 at 14:45
  • cannt find beforeselect function for grid – Mir Gulam Sarwar Jun 16 '13 at 14:59
  • It's an event, not a function. [Here](http://docs.sencha.com/extjs/4.0.2/#!/api/Ext.grid.Panel-event-beforeselect)'s the correct link. According to your comment, your problem doesn't come from that though. I think we'll need the entire code of your grid definition to find what's wrong. – rixo Jun 16 '13 at 21:11