Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handsOnTable cell coloring

I have a Handsontable table filled with data and already rendered

After checking the cells, I have located a couple of cells of interest and would like to color them - is there a good way to do this using the Handsontable code?

Please note this is after loading and rendering the table

Edit:

The table is rendered with basic options:

$container.handsontable({
    startRows: 8,
    startCols: 6,
    rowHeaders: true,
    colHeaders: true,
    minSpareRows: 1,
    minSpareCols: 1,
    //contextMenu: false,
    cells: function (row, col, prop) {
    }
  });

And the data is loaded via Ajax, decode_file.php reads an excel sheet and returns data as JSON:

  $.ajax({
      url: "decode_file.php",
      type: 'GET',
      success: function (res) {
        handsontable.loadData(res.data);
        console.log('Data loaded');
      },
      error: function (res) {
        console.log("Error : " + res.code);
      }
    });

After loading the data, the user clicks a "Process" button and the code looks for a cell with the text "Hello world". Let's say the code finds the text "Hello World" in cell row 4/col 5 and changed the background color of cell row 4/col 5 to red

like image 547
sami Avatar asked Aug 09 '26 19:08

sami


1 Answers

The homepage provides a good example for your purpose:

http://handsontable.com/demo/renderers.html

Just modify the condition (in this case upper/left corner).

cells: function (row, col, prop) {
  if (row === 0 && col === 0) {
    return {type: {renderer: greenRenderer}};
  }
}

and you're done.

like image 144
orange Avatar answered Aug 12 '26 10:08

orange



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!