This topic contains 3 replies, has 2 voices, and was last updated by Jai Jai 6 months, 2 weeks ago.

mDatatable tr background-color


  • softaula
    Participant

    Posts: 25
    Member Reply #15547

    how can I do it to have a personalized background-color in some <tr> of my mDatatable? (html datatable)

    If I add the style in the tr, it is deleted so I guess I should do it by javascript

    My background-color has to be set dinamically so a hardcode color can not be set in the javascript

    Thanks!

    Jai
    Jai
    Keymaster

    Posts: 2693
    Support Staff Reply #15570

    Hi 🙂

    In your datatable options, can you add rows.callback? And the from the 1st param, you can have the access to the <tr> DOM. You can do modification by js.

    rows: {
    callback: function(row, data, index) {
    if(index % 2 === 0) {
    $(row).css(‘background-color’, ‘red’);
    }
    },
    },

    Thanks


    softaula
    Participant

    Posts: 25
    Member Reply #15575

    Ok thanks it worked. And how can I access to the tr I defined?

    I’d like to do something like:

    <tr data-backgroundcolor=”red”>

    rows: {
    callback: function(row, data, index) {

    $(row).css(‘background-color’, ‘here the background I defined in my tr’);

    },
    },

    Jai
    Jai
    Keymaster

    Posts: 2693
    Support Staff Reply #15590

    Hi 🙂

    Sorry, the data attributes defined in the initial HTML table cannot be retrieved after the datatable being rendered.

    Thanks

You must be logged in to reply to this topic.