Hi team, I have a case where I had to add custom checkbox on a header. This works fine, but I had to hide some headers based on client requirement and then noticed that now the checkbox that was supposed to show up for just one header is showing up in adjacent column too. Here is the jsfiddle showing the behavior: https://jsfiddle.net/7v1zekph/
So the code I have to render the checkbox on the header is this:
afterGetColHeader: (col, TH) => {
if (hot.getColHeader(col) === "B") {
if (!TH.querySelector('#active-toggler')) {
let masterCheckbox = document.createElement("input");
masterCheckbox.setAttribute("id", "active-toggler");
masterCheckbox.setAttribute("type", "checkbox");
TH.appendChild(masterCheckbox);
}
}
}
});
As you can see that I want to render the checkbox only on column “B”, however with hide plugin, after I hide the first column “A”, the checkbox renders for column “C” as well.
I do have a fix for the said issue but just feel like its a hack rather than a solution.
hot.updateSettings({
afterGetColHeader: (col, TH) => {
if (hot.getColHeader(col) === "B") {
if (!TH.querySelector('#active-toggler')) {
let masterCheckbox = document.createElement("input");
masterCheckbox.setAttribute("id", "active-toggler");
masterCheckbox.setAttribute("type", "checkbox");
TH.appendChild(masterCheckbox);
}
} else {
TH.querySelector('#active-toggler')?.remove();
}
}
});
From readability perspective it feel like something is a miss, but maybe I am overthinking it. But if you think there is a cleaner solution please let me know.
Thanks.