The tree list can be selected, but the grid cannot.
Why is that so? Thank you for your reply.
1 Answer, 1 is accepted
0
Accepted
Martin
Telerik team
answered on 27 Oct 2023, 01:24 PM
Hello, JunBeom,
When the Grid is reloaded the rows are also redrawn and new attributes are generated (including the UID). I would suggest using the persistSelection option of the Grid to preserve the selection when you set new data in the component.
I applied it the way you suggested and it works well.
Another thing I'm curious about is why does treeList work differently than Grid?
Neli
Telerik team
commented on 03 Nov 2023, 05:58 PM
Hi JunBeom,
The difference in the behavior is due to that the TreeList select method expects a dataItem as a parameter, while the Grid select method expects the rows as String|Element|jQuery. Here you will find the modified Dojo example where the Grid rows selection is persisted using the indexes - https://dojo.telerik.com/@NeliKondova/ALEVAXiN
Below you will find the modified code marked in yellow:
$('#button2').on('click', function() {
// 선택된 항목의 고유 식별자를 저장할 배열let selectedIds = [];
// 현재 선택된 항목의 고유 식별자를 저장let selectedRows = grid.select();
selectedRows.each(function(index, element) {
let dataItem = grid.dataItem(element);
selectedIds.push($(element).index());
});
// 데이터를 다시 로드한 후에 선택된 항목을 찾아 선택
grid.dataSource.data(data);
selectedIds.forEach(function(index) {
let selectedRow = grid.table.find("tr:eq("+index+")");
grid.select(selectedRow);
});
});