onrowselection is not working in LWC Ligthning-datable with pagination. Suppose I have 22 records and i am displaying 10 records per page. If i select 2nd and 3rd row of first page then ids get added in array 'selectedRows' (below is the code for reference) and once i click on next, then 2nd and 3rd row of next(2nd) page gets selected automatically and ids get replaced in this.selectedRows.
rowSelection(event) {
let selectedRow = event.detail.selectedRows;
this.selectedRows = [];
for (let i = 0; i < selectedRow.length; i++) {
if (!selectedRow.includes(selectedRow[i].id)) {
this.selectedRows.push(selectedRow[i].Id);
console.log('this.selectedRows: ', this.selectedRows);
}
}
}