在extjs grid的配置项中,有两个配置项和选择有关:
selModel示例:
xtype: "grid",
store: myStore,
selModel: {
selection: "rowmodel",
mode: "MULTI"
},
columns: [
{ xtype: "rownumberer", text: "行号", width: 50 },
{ text: "姓名", dataIndex: "Name" },
{ text: "年龄", dataIndex: "Age" }
]
selType示例:
xtype: "grid",
store: myStore,
selType: "checkboxmodel",
columns: [
{ xtype: "rownumberer", text: "行号", width: 50 },
{ text: "姓名", dataIndex: "Name" },
{ text: "年龄", dataIndex: "Age" }
]
上面已经介绍了如何进行选择,下面就是实际的多选了。默认情况下extjs grid的选择模型为rowmodel,我们可以通过rowmodel进行行选择(还有一个cellmodel,是用来进行单元格选择的)。
rowmodel默认的选择模型为单行的选择,也就是我们最开始看到的,只能选中一行,要想让它支持多行选择,就要进行相应的配置:
selModel: {
selection: "rowmodel",
mode: "MULTI"
}
注意配置项mode,这家伙用来控制是单行选择还是多行选择的,可用的值有3个:
使用选择框的选择模型是checkboxmodel,来看看下面的代码:
xtype: "grid",
store: myStore,
selModel: Ext.create("Ext.selection.CheckboxModel", {
injectCheckbox: 1,//checkbox位于哪一列,默认值为0
mode: "single",//multi,simple,single;默认为多选multi
checkOnly: true,//如果值为true,则只用点击checkbox列才能选中此条记录
allowDeselect: true,//如果值true,并且mode值为单选(single)时,可以通过点击checkbox取消对其的选择
enableKeyNav: true
}),
columns: [
{ xtype: "rownumberer", text: "行号", width: 50 },
{ text: "姓名", dataIndex: "Name" },
{ text: "年龄", dataIndex: "Age" }
]
要得到选中行,我们首先要找到grid,然后得到grid的selectionModel,然后再找到选择行,代码如下:
var grid = win.down("grid");
var records = grid.getSelectionModel().getSelection();//数组
Ext.MessageBox.alert("提示", records.length);
原文:https://www.cnblogs.com/xsSystem/p/13172766.html