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. Bootstrap 巨幕页头缩略图和警告框组件

    一.巨幕组件 //在固定的范围内,有圆角 <div class="container"> <div class="jumbotron"> ...

  2. pro7

    1.本次课学习到的知识点: 函数的作用 确定函数的功能 定义函数 调用函数 2.实验过程中遇到的问题及解决方法: 定义函数时 变量的定义会出现混乱 通过看例题 多练习 逐渐熟悉 需从数学角度解决问题时 ...

  3. TP自带的缓存机制

    原文章出处: http://blog.163.com/liwei1987821@126/blog/static/172664928201422133218356/ 动态缓存  Cache缓存类 vie ...

  4. Makefile使用总结

    1. Makefile 简介 Makefile 是和 make 命令一起配合使用的. 很多大型项目的编译都是通过 Makefile 来组织的, 如果没有 Makefile, 那很多项目中各种库和代码之 ...

  5. NDK编译FreeImage

    参考了 以下2篇文章 并作了一小点修改 http://recursify.com/blog/2013/05/25/building-freeimage-for-android http://blog. ...

  6. Apache Commons Codec 编码解码

    Apache Commons Codec jar包官方下载地址 下载解压后把commons-codec-1.9.jar 放到lib中 关于SHA1算法的介绍可以参看Wiki:http://en.wik ...

  7. pod》error:The dependency `` is not used in any concrete target

    内容提要: podfile升级之后到最新版本,pod里的内容必须明确指出所用第三方库的target,否则会出现The dependency `` is not used in any concrete ...

  8. 解决libc.so.6: version `GLIBC_2.14' not found问题

    今天centos新机器上运行项目的时候出现题目所示的错误,搜索后发现是底层glibc 版本太低导致. strings /lib64/libc.so.6 |grep GLIBC_ 使用上面的命令发现 g ...

  9. angularJs之模块化

    <!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Cont ...

  10. Spring第12篇—— Spring对Hibernate的SessionFactory的集成功能

    由于Spring和Hibernate处于不同的层次,Spring关心的是业务逻辑之间的组合关系,Spring提供了对他们的强大的管理能力, 而Hibernate完成了OR的映射,使开发人员不用再去关心 ...