Is there a property to obtain cell content in Grid?

I’m trying to determine if a cell has content in Grid, but I can’t find a property that will reveal this. Is there a way, something like:

var sth = grid.cellContent(row.id, column.id)

You need to use the data collection helper. I use this to pinpoint an exact row/col to determine if any data exists (remove the ‘length’ if you want the actual data):

if(grid.data.getItem(grid.data.getId(row_Num)).Col_ID.length) {
console.log(“cell contains data = true”);
}

Here is snippet: https://snippet.dhtmlx.com/cw355xje

Thank you for the snippet. I’ve copied it and am working with it now.

So the point that I think I’m stuck on here is how to find the INDEX of a selected cell? (or any cell for that matter).

I tried getting it from the selection like this, but it returns undefined.

const selectedCell = grid_hours.selection.getCell();
console.log('seleted idx '+selectedCell.indexOf);

I’m able to get the column and row straight away with these:

grid_hours.selection.getCell().row.id
grid_hours.selection.getCell().column.id

But to access the text with getItem() I need to supply an index of the cell.

I tried using getId() but it also requires an index. I tried just counting cells left to right and putting that number in, but it comes back undefined if I put a number higher than the number of rows (minus 1), so it appears getId() is onl returning the index of the selected row.

I entered this with 3 rows of data (and twelve columns):

console.log('getId 0 = '+grid_hours.data.getId(0));
console.log('getId 1 = '+grid_hours.data.getId(1));
console.log('getId 2 = '+grid_hours.data.getId(2));
console.log('getId 3 = '+grid_hours.data.getId(3));

…and the result was:

getId 0 = u1677529998307
getId 1 = u1677529998308
getId 2 = u1677529998309
getId 3 = undefined

…so how do we derive the cells index value from a rowid/columnid or from a selection event?

I think the logical follow up to that question is, how do I derive the index of any cell, such as the one to the left or the one to the right?

Thank you all for your time,

Hello. I think you may want the ‘AfterSelect’ event. This gives you the object for the cell (row and column).

grid.selection.events.on(“AfterSelect”, function(row, col){
console.log(“afterSelect”, row, col);
});

Full snippet (w/ ID): https://snippet.dhtmlx.com/ubxcftw6

Thank you for that. That solves a different issue :slight_smile: I think I need to readjust how I’m approaching this. I’m going to try working with this afterSelect() for a bit.

Please, note, that the getItem() operates with the item ID not with the index: