如何解决在 angular slickgrid 中,从另一个页面路由或更改网格数据时 enablecheckboxselector:true 不起作用
我有一个下拉列表,在下拉列表中的值更改时,我正在使用新数据加载网格并调用 setGridOptions() 再次设置所有网格选项。我有 enablecheckboxselector:true 但复选框也没有出现。 令人惊讶的是,只要我单击任何列对其进行排序,就会显示复选框。任何人都可以请提出解决方案。谢谢!
解决方法
答案与您提出的其他 SO 问题 here 大致相同。所以这似乎是重复的,答案是
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)
}
}
如果这不起作用,您可以尝试我昨天在类似问题中回答的其他解决方案here,答案中的这一部分(如果您添加/删除复选框,这可能对您有用列动态,它写在代码注释和完整的解释然后阅读其他 SO here)
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
可能用于重新同步列定义,但我不确定我是否想直接将其放入库中,使用它应该是安全的您的网格,但我不确定直接在 lib 中的结果(我可能不想在每种网格选项更改时重新加载列),可能是这样的(未经测试)
<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];
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。