Change datatable Column color on click

Change datatable Column color on click

knight08knight08 Posts: 3Questions: 2Answers: 0
edited October 2023 in Free community support

Can we change the column color in a datatable on click? example: color of column changes to yellow when clicked on table heading.

Answers

  • rf1234rf1234 Posts: 2,990Questions: 87Answers: 421
    edited October 2023

    Sure whenever the data table is drawn add your event handler.

    Check "Reference", "Events" for the "draw" event and other suitable events.

    colum().nodes() could be useful to select the column that you want to change.
    https://datatables.net/reference/api/column().nodes()

    To select a table header you could assign a class in your <th> tag in your HTML and then take it from there:

    $( table.column(".yourColumn").header() ).click( ... change the color etc.
    
  • knight08knight08 Posts: 3Questions: 2Answers: 0

    this helped. thank you

Sign In or Register to comment.