ExtJS 4 - Grid - Disable rowselection for specific column

坚强是说给别人听的谎言 提交于 2019-12-01 03:47:08

问题


I have created a grid with extjs 4. The selection.CheckboxModel is implemented to. This means that the row is selected/deselected wherever you click on the particular row. Now i want to disable this selection on the last column since it contains custom buttons. (I don't want to select the row if a button is clicked).

Any idea's how to do this?

Many thanks in advance!


回答1:


This is actually a tricky little problem, if only because Sencha documentation is lacking.

The CheckboxModel does indeed have a beforeselect event inherited from Ext.selection.RowModel. However, there's no easy way to get the column index because frankly, that's the point of the RowModel.

However, there's an undocumented event in Ext.view.Table (which your grid will inherit) called beforecellmousedown. Here's the event parameters:

  1. view: The view of your grid
  2. cell: The cell that was clicked
  3. cellIndex: Index of the cell
  4. record: The store record associated with the cell
  5. row: The row of the cell
  6. rowIndex: Index of the row
  7. eOpts: Standard event option event

So you would probably try something like this:

viewConfig: {
    listeners: {
        beforecellmousedown: function(view, cell, cellIdx, record, row, rowIdx, eOpts){
            if(cellIdx === indexOfLastColumnInGrid){
                return false;
            }
        }
    }
}

Both the cell and row indexes are zero-based.




回答2:


listeners: {
    beforecellmousedown: function(view, cell, cellIdx, record, row, rowIdx, eOpts) {
        if (String(eOpts.getTarget()) == '[object HTMLButtonElement]') {
            return false;
        }
    }
}

Thanx Eric. This i the final solution!




回答3:


Read this article http://www.learnsomethings.com/2012/01/12/stopping-a-checkbox-from-allowing-select-in-an-extjs-4-grid-checkbox-column-via-the-ext-selection-checkboxmodel/ I hope it will help you.



来源:https://stackoverflow.com/questions/9534077/extjs-4-grid-disable-rowselection-for-specific-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!