admin管理员组文章数量:1291735
I have a kendo-grid with a (selectionChange) attribute where I get my selection using a custom selectionService.ts:
(selectionChange)="selectionService.onSelectionChange($event)"
My selectionService is custom as I have different functionality based on if one item [1] or exactly two [1,2] is selected. If a 3rd row is selected, the third row should shift out the first, so the row would be [2,3]. My code here:
public onSelectionChange(event: SelectionEvent): void {
if (this.selectedItems!.length + event.selectedRows!.length > 2) {
this.selectedItems.shift();
}
for (let row of event.selectedRows!) {
this.selectedItems!.push(row.dataItem);
}
this.selectedItems = this.selectedItems!.filter(
item => !event.deselectedRows!.some(row => row.dataItem === item)
);
}
My problem is my selection works, but visually kendo still keeps the previously selected rows still selected as well. How do I make it so if a 3rd item is selected, the grid also deselects this item?
Stackblitz example:
I have a kendo-grid with a (selectionChange) attribute where I get my selection using a custom selectionService.ts:
(selectionChange)="selectionService.onSelectionChange($event)"
My selectionService is custom as I have different functionality based on if one item [1] or exactly two [1,2] is selected. If a 3rd row is selected, the third row should shift out the first, so the row would be [2,3]. My code here:
public onSelectionChange(event: SelectionEvent): void {
if (this.selectedItems!.length + event.selectedRows!.length > 2) {
this.selectedItems.shift();
}
for (let row of event.selectedRows!) {
this.selectedItems!.push(row.dataItem);
}
this.selectedItems = this.selectedItems!.filter(
item => !event.deselectedRows!.some(row => row.dataItem === item)
);
}
My problem is my selection works, but visually kendo still keeps the previously selected rows still selected as well. How do I make it so if a 3rd item is selected, the grid also deselects this item?
Stackblitz example:
https://stackblitz/edit/angular-pe3m9kdq-6wwuibrm
Share Improve this question edited Feb 13 at 15:04 B.Quaink asked Feb 13 at 13:45 B.QuainkB.Quaink 5861 gold badge5 silver badges25 bronze badges1 Answer
Reset to default 2I have updated your example and used row selection persistence to maintain the selection state in the Grid. Here is the result that meets your requirements:
https://stackblitz/edit/angular-pe3m9kdq-i1qt5ben
I hope this helps.
本文标签: htmlUpdate kendo angular grid selected rows by (selectionChange) using custom serviceStack Overflow
版权声明:本文标题:html - Update kendo angular grid selected rows by (selectionChange) using custom service - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741537555a2384118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论