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

fix broken selection when the first column is invisible #4410

Merged

Conversation

azmy60
Copy link
Collaborator

@azmy60 azmy60 commented Feb 22, 2024

When starting tabulator with SelectRange enabled, the selection is not on the top left. This is because we have a table that the first column is invisible and that column get processed, which shouldn't.

Demo: https://jsfiddle.net/zqd0kgwr/

@olifolkerd olifolkerd changed the base branch from master to 6.0 March 11, 2024 13:38
@olifolkerd
Copy link
Owner

olifolkerd commented Mar 11, 2024

Hey @azmy60

Thanks for the fix, i will include it in the 6.0 release.

Just a quick note on your variable definitions, as I've had to tidy these up on some of your past commits. It is considered bad practice to declare a variable anywhere other than at the top of the function if using a var (let can be defined at top of logical block). When you define them later in the function you are making more work for the interpreter as it has to hoist them to the top of the function anyway before it can execute the code.

You should define all variables used in a function at the top of the function, then assign them later if needed.

To be clear, this is how your PR has your code structured:

resetRanges() {
    ....
    if(this.table.rowManager.activeRows.length){
        var visibleCells = this.table.rowManager.activeRows[0].cells.filter((cell) => cell.column.visible);
        cell = visibleCells[this.rowHeader ? 1 : 0];
    }
}

It should be:

resetRanges() {
    var visibleCells;
    ....
    if(this.table.rowManager.activeRows.length){
        visibleCells = this.table.rowManager.activeRows[0].cells.filter((cell) => cell.column.visible);
        cell = visibleCells[this.rowHeader ? 1 : 0];
    }
}

Not only does this reduce the work on the JS interpreter (it has to do this hoisting anyway before it can execute the code), it makes it clear to other developers what variables are available inside the function call.

Cheers

Oli :)

@olifolkerd olifolkerd merged commit f99e5fa into olifolkerd:6.0 Mar 11, 2024
2 of 3 checks passed
@azmy60
Copy link
Collaborator Author

azmy60 commented Mar 12, 2024

Ah, I see why that needs to be on top. Thanks!

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.

2 participants