Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes page toggling #31

Merged
merged 3 commits into from
Jun 17, 2021
Merged

fixes page toggling #31

merged 3 commits into from
Jun 17, 2021

Conversation

vmcvlad
Copy link
Contributor

@vmcvlad vmcvlad commented Jun 16, 2021

No description provided.

this.state.selected.splice(index, 1);
if(!this.state.pageSelected) {
if(index !== -1) {
this.state.selected.splice(index, 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes the case where the selected array would be unnecessarily spliced for each unselected element

Copy link
Contributor

@aocneanu aocneanu Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's refactor the whole method to something more readable like:

toggleRowSelect(row) {
    if (this.isChild(row)) {
        return;
    }

    const index = this.state.selected
        .findIndex(id => id === row[this.template.dtRowId]);

    if (index === -1 && this.state.pageSelected) {
        this.state.selected.push(row[this.template.dtRowId]);
    } else if (index !== -1 && !this.state.pageSelected) {
        this.state.selected.splice(index, 1);
    }
},

@vmcvlad vmcvlad merged commit 3d36972 into master Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants