new Ext.grid.CellSelectionModel({
last : false, // 上一次选中的单元格
selections : [], // 选择区缓存
handleMouseDown: function (grid, row, col, event) {
var isSelected;
if (event.button !== 0 || this.isLocked())
return;
if (event.shiftKey && this.last !== false) { //是否按下shift
this.selectMatrix(row, col);
grid.getView().focusCell(row, col);
return;
} else if (event.ctrlKey) { //是否按下ctrl
isSelected = this.isSelected(row, col);
if (col === 0 && this.last[1] === 0) {
isSelected ? this.deselectRow(row) : this.selectRow(row, true);
}
if (isSelected) { // 是否已被选中,是则反选,否则选中
this.deselectCell(row, col);
} else {
this.selectCell(row, col, true);
this.last = [row, col];
}
} else if (col === 0) { // 第一列是NumberColumn 点击则选择列
this.selectRow(row);
this.last = [row, col];
} else { // 选择单个单元格
this.selectCell(row, col);
this.last = [row, col];
}
if (this.matrix)
delete this.matrix;
},
// 清除选择区内所以单元格被选中的样式
clearCellSelections: function () {
var l = this.selections.length,
i = 0;
for (; i < l; i++) {
cell = this.selections[i];
this.grid.view.onCellDeselect(cell[0], cell[1]); // GridView的内置方法,改变某单元格样式
}
this.selections.length = 0;
},
// 反选指定单元格,并清除相应选择区缓存
deselectCell: function (row, col, isDelrow) {
var l = this.selections.length,
i = 0, n = 0;
if (this.selections) {
this.grid.view.onCellDeselect(row, col); // GridView的内置方法,改变某单元格样式
for (; i < l; i++) {
cell = this.selections[i];
if (row !== cell[0] || col !== cell[1]) {
this.selections[n++] = this.selections[i];
} else if (!isDelrow) { // 是否删除行
this.selections.splice(i, 1);
return;
}
}
this.selections.length = n;
}
},
// 根据选择区缓存中的数据,判断是否被选中
isSelected: function (row, col) {
var l = this.selections.length,
i = 0;
for (; i < l; i++) {
cell = this.selections[i];
if (row === cell[0] && col === cell[1]) {
return true;
}
}
return false;
},
// 选中某个单元格
selectCell: function (rowIndex, colIndex, keepExisting, preventViewNotify, preventFocus) {
if (this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false) {
if (!keepExisting)
this.clearCellSelections();
this.selections.push([rowIndex, colIndex]); // 加入选择区缓存
if (!preventViewNotify) {
var v = this.grid.getView();
v.onCellSelect(rowIndex, colIndex); // GridView的内置方法,改变某单元格样式
if (preventFocus !== true) {
v.focusCell(rowIndex, colIndex);
}
}
this.fireEvent("cellselect", this, rowIndex, colIndex);
this.fireEvent("selectionchange", this, this.selection);
}
},
// 选中某一行
selectRow: function (rowIndex, keepExisting) {
var clen = this.grid.getColumnModel().getColumnCount(),
c = 0;
if (!keepExisting)// 是否清空所有已选择的单元格
this.clearCellSelections();
for (; c < clen; c++) {
this.selectCell(rowIndex, c, true);
}
},
// 某行反选
deselectRow: function (row) {
var clen = this.grid.getColumnModel().getColumnCount(),
c = 0;
if (this.selections) {
for (; c < clen; c++) {
this.deselectCell(row, c, true);
}
}
},
// 按shift键调用的方法,选中一个矩形区域内所有的单元格
selectMatrix: function (row, col, keepExisting) {
// 以上一次被选择的单元格为起点,形成一个矩阵区域
var r = this.last[0],
c = this.last[1];
if (!keepExisting)
this.clearCellSelections();
if (r > row) {
var temp = row;
row = r;
r = temp;
}
if (col === 0 && c === 0) { // 若选择了第一列序号,则选择行
for (; r <= row; r++) {
this.selectRow(r, true);
}
return;
}
if (c > col) {
var temp = col;
col = c;
c = temp;
}
for (; r <= row; r++) {
for (var i = c; i <= col; i++) {
this.selectCell(r, i, true);
}
}
this.matrix = { // 矩形区域选择区数据
start: [r, c],
end: [row, col]
};
}
}),

extjs grid 单元格 多选的更多相关文章

  1. Extjs grid 单元格事件

    celldblclick: function (view, td, cellIndex, record, tr, rowIndex, e, eOpts) { //extjs 4.2下,有时出现,多次不 ...

  2. Extjs grid 单元格编辑

    实现grid勾选后出现编辑按钮,通过增加一个字段checked来控制 事件如下: selectionchange: function (thi, selected, eOpts) { for (var ...

  3. ExtJs4学习(十)Grid单元格换色和行换色的方法

    Grid单元格换色 { text:'类别', dataIndex:'type', align:'center', renderer:function(value,metaData){ console. ...

  4. 取得grid单元格里刚输入的文本,未保存的文本

    取得grid单元格里刚输入的文本内容,未保存的文本,正在输入的值,正在编辑的值,编辑框 dbgrid->DataSource->DataSet->UpdateRecord(); pr ...

  5. ExtJS4.x Grid 单元格鼠标悬停提示

    //每一个列都会出现鼠标悬浮上去显示内容 /** * //适用于Extjs4.x * @class Ext.grid.GridView * @override Ext.grid.GridView * ...

  6. 点击grid单元格弹出新窗口

    实现功能:点击指定单元格后会弹出新窗口,并且最后一行合计不会触发单元格触发函数 <script type="text/javascript"> grid.on('cel ...

  7. 关于Kendo的Grid 单元格样式

    <!DOCTYPE html><html style="height: 100%;"><head><meta http-equiv=&qu ...

  8. Ext grid单元格编辑时获取获取Ext.grid.column.Column

    item2.width = 80; //item2.flex = 1; item2.align = 'center'; item2.menuDisabled = true; //禁止显示列头部右侧菜单 ...

  9. ExtJs grid单选,多选

    一. selType : 'checkboxmodel',singleSelect : true, // 单选multiSelect : true, // 多选singleSelects:['edit ...

随机推荐

  1. mysql sql技巧篇

    1.left join 需要注意的事项 以左表为基准,匹配右表,如果右表匹配了两条,那么,就生成两条记录,而这两条记录的坐表信息都是一样的. 之前误以为,右表不会影响记录的条数.select 部分,不 ...

  2. sqlserver 通过convert取得指定格式的时间

    http://msdn.microsoft.com/zh-cn/library/ms187928(v=sql.105).aspx CONVERT(NVARCHAR(10),Created,112) 不 ...

  3. Python的运行

    1.在命令行中运行 2.使用shell(IDLE) 3.新建.py脚本 只要是编辑器都可以 4.脚本在IDLE中运行 5.在windows下的cmd下运行脚本

  4. javax.management.NotCompliantMBeanException

    public interface QueueMBean { } 假如接口名叫 XMBean ,那么实现名就必须一定是X,而且是大小写敏感的. public class Queue implements ...

  5. 【Java 进阶篇】【第二课】异常处理

    概念 异常处理的存在是为了:   允许程序员跳过无法处理的问题,继续开发后续的工作,或根据异常做出更加聪明的处理方式. Java中存在一类对象叫“异常对象”. 当异常情况发生时,就会暗战预先的设定,抛 ...

  6. TEST指令

    In the x86 assembly language, the TEST instruction performs a bitwise AND on two operands. The flags ...

  7. caption,为表格增加标题和摘要

    格式: <table summary="***"> <caption>***</caption> <tr> </tr> ...

  8. Effective Project Communications

    I was recently invited to speak at a conference in Singapore on Effective Project Communications. I' ...

  9. 【转】TableLayout(表格布局)

    转自:http://www.cnblogs.com/zhangs1986/archive/2013/01/17/2864536.html TableLayout(表格布局) 表格布局模型以行列的形式管 ...

  10. sell- 获取邮箱的后缀

    1. public static void main(String[] args) { System.out.println(getEmailSuffix("jim_chen28270@16 ...