JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Data Grid › Change cell value based on other cell value › Reply To: Change cell value based on other cell value
Still haven’t found out why this happens, but in attempt to try and update the cell template in some other way, a new question emerged.
I have this function that I call instead (to set the cell template), when the grid has been loaded (called with no arguments).
If I delete an attachment, which means that the dataField ‘attachment_count’ for the given row, should be decreased by 1, I call the same function but this time with the row-number and an update-value (-1 in this case).
However, se template is used for the initial grid load, but when I called the function later on, nothing happens to the cell templates.
function refresh_grid_attachment_icons(row, count_update)
{
if (row != null && row != undefined && count_update != null && count_update != undefined)
{
const current_count = parseInt(grid.getCellValue(row, 'attachment_count'));
const new_count = (current_count + count_update);
console.log('current_count: '+ current_count +' | new_count: '+ new_count); // after an attachment delete, this line shows e.g. "current_count: 1 | new_count: 0".
grid.setCellValue(row, 'attachment_count', new_count); // and so sets the value of the cell to 0. (it is a number field).
}
var col_index_attachments = -1;
for (var i = 0; i < grid.rows.length; i++)
{
if (col_index_attachments < 0 || col_index_attachment_count < 0)
{
for (var x = 0; x < grid.rows[i].cells.length; x++)
{
if (grid.rows[i].cells[x].column.dataField == 'Attachments')
{
col_index_attachments = x;
break;
}
}
}
if (parseInt(grid.getCellValue(i, 'attachment_count'), 10) < 1)
{
grid.rows[i].cells[col_index_attachments].setProperties({ template: '' });
}
else if (parseInt(grid.getCellValue(i, 'attachment_count'), 10) == 1)
{
grid.rows[i].cells[col_index_attachments].setProperties({ template: '<some_fa_icon>' });
}
else if (parseInt(grid.getCellValue(i, 'attachment_count'), 10) > 1)
{
grid.rows[i].cells[col_index_attachments].setProperties({ template: '<some_other_fa_icon>' });
}
}
grid.refresh();
}
-
This reply was modified 1 year, 5 months ago by
Peter.