0

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);
            }
        }
    }

1 Answer 1

0

Can you try to replace the for loop like this :

        for (let i = 0; i < selectedRow.length; i++) {
            if (!selectedRows.includes(selectedRow[i].id)) {
                this.selectedRows.push(selectedRow[i].Id);
                console.log('this.selectedRows: ', this.selectedRows);
            }
        }

And remember that js is a case-sensitive language, id is different from Id

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .