https://snippet.dhtmlx.com/ad6roqsx?text=grid.Selection
Please replace the javascript with below, try to select multiple cells, then click the radio button. The alerted count of the selected cells is one more than the real count.
let grid;
const config = {
columns: [
{ id: "country", header: [{ text: "Country" }] },
{ id: "population", header: [{ text: "Population" }] },
{ id: "yearlyChange", header: [{ text: "Yearly Change" }] },
{ id: "netChange", header: [{ text: "Net Change" }] },
{ id: "density", header: [{ text: "Density (P/Km²)" }] },
{ id: "area", header: [{ text: "Land Area (Km²)" }] },
{ id: "migrants", header: [{ text: "Migrants (net)" }] },
{ id: "fert", header: [{ text: "Fert. Rate" }] },
{ id: "age", header: [{ text: "Med. Age" }] },
{ id: "urban", header: [{ text: "Urban Pop" }] }
],
adjust: true,
data: JSON.parse(JSON.stringify(dataset)),
multiselection: true,
selection: "cell",
};
function createGrid() {
if (grid) {
grid.destructor();
}
grid = new dhx.Grid("grid", config);
grid.selection.setCell(grid.data.getItem(grid.data.getId(0)), grid.config.columns[0]);
}
createGrid();
const selector = document.querySelectorAll("[name=selection]");
for (let index = 0; index < selector.length; index++) {
selector[index].addEventListener("change", function (e) {
alert(grid.selection.getCells().length)
});
}