[英]Set initial selected rows in Angular Kendo UI grid with rowSelected
I have a Kendo UI Grid where you are able to select individual rows by clicking a checkbox which adds them to an array;我有一个 Kendo UI Grid,您可以通过单击将它们添加到数组的复选框来选择单个行; however, I am wanting to initially set selected rows based on whether or not the dataItem
for each row is in a specified array called selectedAccounts
.但是,我想根据每行的dataItem
是否在名为selectedAccounts
的指定数组中来初始设置选定的行。
I have tried using [rowSelected]="isRowSelected"
, but using this method would not allow me to check/uncheck the selection checkbox.我曾尝试使用[rowSelected]="isRowSelected"
,但使用此方法不允许我选中/取消选中选择复选框。
I need to be able to set the selected condition initially and change the selection if needed.我需要能够最初设置所选条件并根据需要更改选择。 It's also worth noting that I do not have an issue when I start with nothing in selectedAccounts
.还值得注意的是,当我从selectedAccounts
任何内容开始时,我都没有问题。
It turns out that I had everything set up correctly, but I was wrong with the way I was using isRowSelected
in the typescript file.事实证明,我已经正确设置了所有内容,但是我在打字稿文件中使用isRowSelected
的方式有误。 I originally had:我原来有:
public isRowSelected = (e: RowArgs) => this.selectedAccounts.indexOf(e.dataItem) >= 0;}
The above code would always return false while still showing selectedAccounts
correctly.上面的代码将始终返回 false,同时仍然正确显示selectedAccounts
。
After making the changes below, selectedAccounts
could be read properly and allowed me to toggle the checkboxes as needed while updating the selectedAccounts
array and without causing any additional problems.进行以下更改后,可以正确读取selectedAccounts
并允许我在更新selectedAccounts
数组时根据需要切换复选框,而不会导致任何其他问题。
public isRowSelected = (e: RowArgs) => {
return this.selectedAccounts.find(f => e.dataItem.accountId === f.accountId) ? true : false;
}
I hope this answer is helpful for others.我希望这个答案对其他人有帮助。 I have updated the stackblitz to reflect the correct code.我已经更新了stackblitz以反映正确的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.