Checkbox Column checked state not working when virtual dom is enabled
See original GitHub issueDescription 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:
- Go to above link.
- Click on select all checkbox in the checkbox column header.
- 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:
- Created 4 years ago
- Comments:27 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @angeliski ,
I changed
selectable
totrue
and now the Deselection Error is not logged.Thanks, Abdul
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 theheaderClick
logic to update the original array and force a redraw after the update.