[英]How to suppress range selection for some columns in ag-grid
ag-grid
has a number of properties: enable*
. ag-grid
有许多属性: enable*
。 Columns have a number of properties: suppress*
.列有许多属性:
suppress*
。 Setting a suppress*
for a column has the effect of disabling the effects of some enable*
property on the grid, for that column.为列设置
suppress*
禁用该列的某些enable*
属性对网格的影响。
For example:例如:
var columnDefs = [
{field: 'athlete', suppressMovable: true, width: 150, cellClass: 'suppress-movable-col'},
{field: 'age', lockPosition: true, cellClass: 'locked-col'},
{field: 'country', width: 150}
];
var gridOptions = {
suppressDragLeaveHidesColumns: true,
columnDefs: columnDefs,
defaultColDef: {
width: 100
}
};
In the above example, the 'athlete' column is not movable due to suppressMovable:true
.在上面的示例中,“运动员”列由于
suppressMovable:true
移动suppressMovable:true
是不可移动的。 All of the other columns are movable.所有其他列都是可移动的。
I have a grid with enableRangeSelection: true
我有一个带有
enableRangeSelection: true
的网格
I would like to prevent the first column from being included in a range selection.我想防止第一列包含在范围选择中。 However, no column property exists called
suppressRangeSelection
.但是,不存在称为
suppressRangeSelection
列属性。
How can I prevent the user from including the first column in range?如何防止用户在范围内包含第一列?
Does not seem like ag-grid allows such behavior, but I managed to do so using Range Selection API:似乎 ag-grid 不允许这种行为,但我设法使用范围选择 API 这样做:
var gridOptions = {
columnDefs: columnDefs,
enableRangeSelection: true,
rowData: null,
onRangeSelectionChanged: event => {
var cellRanges = event.api.getCellRanges();
if (!cellRanges || cellRanges.length === 0) return;
var excludeColumn = cellRanges[0].columns.find(
el => el.getColId() === 'athlete'
);
if (!excludeColumn) return;
var rangeParams = {
rowStartIndex: cellRanges[0].startRow.rowIndex,
rowStartPinned: cellRanges[0].startRow.rowPinned,
rowEndIndex: cellRanges[0].endRow.rowIndex,
rowEndPinned: cellRanges[0].endRow.rowPinned,
columns: cellRanges[0].columns
.map(el => el.getColId())
.filter(el => el !== 'athlete'),
};
event.api.clearRangeSelection();
event.api.addCellRange(rangeParams);
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.