question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkbox Column checked state not working when virtual dom is enabled

See original GitHub issue

Description of the Bug I Implemented checkbox column following the issue #1938 and fixed the bugs in that implementation. I have virtual dom enabled in my Tabulator table and now if I click on checkbox column header to select all rows in the table, Tabulator changes the checked state of checkboxes only in the rows visible in the screen. If I scroll down new rows will get replaced in the grid and the checkboxes in that row are not checked.

Tabulator Info

  • version 4.2.7
  • Below is the code for checkbox column setup:
{
                            title: 'Select <br/> All <br/> <input type="checkbox" class="select-all-row" aria-label="select all rows" />',
                            field: 'IsSelected',
                            formatter: function (cell, formatterParams, onRendered) {
                                return '<input type="checkbox" class="select-row" aria-label="select this row" />';
                            },
                            width: 50,
                            headerSort: false,
                            headerFilter: false,
                            cssClass: 'text-center',
                            frozen: true,
                            tooltips: false,
                            resizable: false,
                            cellClick: function (e, cell) {
                                var element = cell.getElement();
                                var chkbox = element.querySelector('.select-row');
                                if (cell.getData().IsSelected) {
                                    cell.getRow().deselect();
                                    document.querySelector('.select-all-row').checked = false;
                                } else {
                                    cell.getRow().select();
                                    if (cell.getColumn().getTable().getSelectedRows().length === cell.getColumn().getTable().getDataCount()) {
                                        document.querySelector('.select-all-row').checked = true;
                                    }
                                }
                                chkbox.checked = !cell.getData().IsSelected;
                                cell.getData().IsSelected = !cell.getData().IsSelected;
                            },
                            headerClick: function (e, column) {
                                if (column.getTable().getSelectedRows().length !== column.getTable().getDataCount()) {
                                    document.querySelectorAll('.select-row,.select-all-row').forEach(cb => cb.checked = true);
                                    column.getTable().selectRow();
                                } else {
                                    document.querySelectorAll('.select-row,.select-all-row').forEach(cb => cb.checked = false);
                                    column.getTable().deselectRow();
                                }
                                column.getCells().forEach(cell => cell.getData().IsSelected = !cell.getData().IsSelected);
                            }
                        }

Working Example Js Fiddle Demo

To Reproduce Steps to reproduce the behavior:

  1. Go to above link.
  2. Click on select all checkbox in the checkbox column header.
  3. Scroll down to see the check boxes not getting checked.

Expected behavior All the checkbox needs to be checked when I click header checkbox irrespective of virtual dom

Desktop

  • OS: Windows10
  • Browser : Chrome
  • Version 72.0.3626.121 (Official Build) (64-bit)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
fingers10commented, Sep 3, 2019

Hey @angeliski ,

I changed selectable to true and now the Deselection Error is not logged.

Thanks, Abdul

2reactions
tentuscommented, Jul 16, 2019

Your issue is that you’re manipulating the dom, not the underlying data, so the selections evaporate when the virtual dom is scrolled.

take a look at this variation: https://jsfiddle.net/m3jpghb8/ I’ve turned on reactiveData, so the original array can be updated and also affect the tabulator data, and then made the formatter look at the data when rendering the checkbox, and then finally tweaked the headerClick logic to update the original array and force a redraw after the update.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to change the status of check box in the react virtual dom
Here is a working version, if i understand correctly. The problem was here checked={this.state.isChecked} . Here is your final codebox.
Read more >
Row selection getting disabled on virtual scrolling ... - jQWidgets
Hi, I have a requirement where checkbox column needs to be in the middle column.So for its implementation I followed the code snippet...
Read more >
HTML DOM Input Checkbox Object - W3Schools
The Input Checkbox object represents an HTML <input> element with type="checkbox". ... checked, Sets or returns the checked state of a checkbox.
Read more >
Checkbox List in React JS with Example - Contact Mentor
React State is declared to maintain the list of all checked items. The code is dynamically updated whenever “setChecked()” is called with the...
Read more >
Table Options - Bootstrap Table
Activate bootstrap table without writing JavaScript. Default: 'table' ... Set false to hide the check-all checkbox in the header row. Default: true.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found