我有一个下拉列表,在更改下拉列表中的值时,我正在使用新数据加载网格并调用 setGridOptions() 再次设置所有网格选项。我有 enablecheckboxselector:true 但复选框也没有出现。令人惊讶的是,只要我单击任何列对其进行排序,就会显示复选框。任何人都可以请提出一个解决方案。谢谢!
1 回答
0
答案与您在此处提出的其他 SO 问题大致相同。所以这似乎是重复的,答案是
angularGridReady(angularGrid: AngularGridInstance) {
this.angularGrid = angularGrid;
this.gridObj = angularGrid.slickGrid;
}
changeGridOptions() {
const isReadyOnly = false; // whatever your code logic is here...
this.angularGrid.slickGrid.setOptions({ enableCheckboxSelector: isReadyOnly });
if (isReadOnly) {
// you also need to remove the column from your column definitions
// you can do that by using slice which will also trigger a dirty change to refresh the grid
this.columnDefinitions = this.columnDefinitions.slice(1); // return all columns without first one (without index 0)
}
}
如果这不起作用,您可以尝试我昨天在类似问题中回答的其他解决方案,这部分来自答案(如果您动态添加/删除复选框列,这可能对您有用,它写在代码注释和完整的解释,然后在这里阅读另一个 SO )
dynamicallyAddTitleHeader() {
//... add your new column
// NOTE if you use an Extensions (Checkbox Selector, Row Detail, ...) that modifies the column definitions in any way
// you MUST use "getAllColumnDefinitions()" from the GridService, using this will be ALL columns including the 1st column that is created internally
// for example if you use the Checkbox Selector (row selection), you MUST use the code below
const allColumns = this.angularGrid.gridService.getAllColumnDefinitions();
allColumns.push(newCol);
this.columnDefinitions = [...allColumns]; // (or use slice) reassign to column definitions for Angular to do dirty checking
}
基本上 Angular-Slickgrid 保留了列定义及其位置的内部引用,如果您直接使用grid.setOptions
您有点绕过 Angular-Slickgrid 并且它不知道列定义更改,您可以强制与 2 建议同步这个答案中写的一段代码。你必须知道并记住的是,Angular-Slickgrid 是 SlickGrid 之上的一个包装器,如果你直接与 SlickGrid 对话,那么在某些情况下(比如这个),Angular-Slickgrid 不会意识到这个变化。
SlickGrid 中还有一个事件onSetOptions
可能用于重新同步列定义,但我不确定我是否想将它直接放在库中,在您的网格中使用它应该是安全的,但我不确定直接在库中的后果(我可能不想在每种网格选项更改时重新加载列),可能是这样的(未经测试)
<angular-slickgrid
gridId="grid"
[columnDefinitions]="columnDefinitions"
[gridOptions]="gridOptions"
[dataset]="dataset"
(onAngularGridCreated)="angularGridReady($event)"
(sgOnSetOptions)="handleOnSetOptions($event.detail.eventData, $event.detail.args)"
</angular-slickgrid>
handleOnSetOptions(e, args) {
const allColumns = this.angularGrid.gridService.getAllColumnDefinitions();
// (or use slice) reassign to column definitions for Angular to do dirty checking
this.columnDefinitions = [...allColumns];
}
于 2021-03-18T15:12:56.380 回答