【发布时间】:2017-03-20 00:05:28
【问题描述】:
有没有一种方法可以为每一行设置行选择复选框,而无需为其配置特殊列?我的意思是为我的 gridOptions 添加属性并查看每行附近的复选框,然后获取所有选定的行? 我阅读的所有文档都显示了如何通过将其添加到特定列来做到这一点。
谢谢,
【问题讨论】:
标签: ag-grid
有没有一种方法可以为每一行设置行选择复选框,而无需为其配置特殊列?我的意思是为我的 gridOptions 添加属性并查看每行附近的复选框,然后获取所有选定的行? 我阅读的所有文档都显示了如何通过将其添加到特定列来做到这一点。
谢谢,
【问题讨论】:
标签: ag-grid
您仍然可以在没有复选框列的情况下进行行选择 - 您可以简单地根据行选择进行选择,也可以在其中渲染带有复选框的列(使用自定义单元格渲染器)。
查看Selection Documentation 了解有关行选择的更多信息,查看Cell Rendering Documentation 了解有关单元格渲染的更多信息
【讨论】:
我知道现在回答这篇文章为时已晚。但这可能对仍在寻找解决方案的人有所帮助。它适用于每行上的复选框选择(单击行上的任意位置以选择复选框)、移位/控制和切换选择。这里我只给出了必要的代码。
vm.gridOptions = {
appSpecific : {},
onRowClicked : onRowClicked,
onGridReady : function() {
let api = vm.gridApi = vm.gridOptions.api;
}
};
function toggleSelect(row) {
row.node.setSelected(!row.node.isSelected(), false);
}
function onRowClicked(row) {
var appSpecific = vm.gridOptions.appSpecific;
var lastSelectedRow = appSpecific.lastSelectedRow;
var shiftKey = row.event.shiftKey;
// if not modifier keys are clicked toggle row
if (!shiftKey) {
toggleSelect(row);
} else if (lastSelectedRow !== undefined) {
if (shiftKey) {
var startIndex, endIndex;
// Get our start and end indexes correct
if (row.rowIndex < lastSelectedRow.rowIndex) {
startIndex = row.rowIndex;
endIndex = lastSelectedRow.rowIndex;
}
else {
startIndex = lastSelectedRow.rowIndex;
endIndex = row.rowIndex;
}
// Select all the rows between the previously selected row and the
// newly clicked row
for (var i = startIndex; i <= endIndex; i++) {
vm.gridApi.selectIndex(i, true, true);
}
}
}
// Store the recently clicked row for future use
appSpecific.lastSelectedRow = row;
getSelection(); // Implement functionality to get selected rows
}
【讨论】: