Change background colour of a datatable cell

Change background colour of a datatable cell

aCoradatatblaCoradatatbl Posts: 16Questions: 7Answers: 0
edited April 2019 in Free community support

Hi
i'm using this syntax to get the cell contents:
var idrow = dTblOverview.row("#"+rowPk);
var cellContent = dTblOverview.cell( idrow, 6 ).data();

I would like to elaborate on this and change the cell (cellContent ) background colour using the same syntax as its post-datatable initialisation and being called from another part of the script.

thanks in advance ...

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @aCoradatatbl ,

    If you use node(), then you can change it easily with jQuery, something like:

    $(dTblOverview.cell(2,2).node()).css({'color':'red'})
    

    Cheers,

    Colin

  • aCoradatatblaCoradatatbl Posts: 16Questions: 7Answers: 0
    edited April 2019

    Thanks for the response Colin,
    Node api? that requires editor doesn't it or am i reading wrong? Im not using editor just datatable with the buttons api - itried something similat to that syntax like:

    dTblOverview.cell( 5, 6 ).css('color', 'yellow')

    is there a datatable function which can reference the cell object to achieve this??

    thanks ...

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Colin gave the wrong link, it should be cell().node(). It is a Datatables API. Did you try Colin's suggestion?

    Kevin

  • aCoradatatblaCoradatatbl Posts: 16Questions: 7Answers: 0

    Ahhah, Yes that worked Kevin, didn't actually try first time since it said Editor API required - thanks for the heads-up.

    Cheers

This discussion has been closed.