How to add and edit markup in table cells

How to add and edit markup in table cells

wry_discontentwry_discontent Posts: 1Questions: 1Answers: 0

I'm populating the table cells with db data, and right now I'm wrapping that string with an html span string to get access to some styles inside the cells. Is there a cleaner way to do that?

I also need to modify some of those styles, but it seems like DataTable offers no way to select anything at all. I have used .rows and .columns and .data and .nodes but none of those give me any access to anything useful. Usually I just get an object indexed by numeric identity (that is, { 0: 0, 1: 1, 2: 2 ...}.

Can these tables be modified at all?

Answers

  • Rob BrunRob Brun Posts: 56Questions: 2Answers: 14
    edited June 2017

    Hi wry_discontent, the way that I style cells in my tables is in the created row call back.
    In the example below I turn the 11th cell in my table row green or red based on a condition found in my table data.

     "createdRow": function (row, data, index) {
        if ( data["InvoiceSent"] === "No" ) {
           $('td', row).eq(11).css( 'background-color', 'rgb(255, 128, 128)');
         } else {
            $('td', row).eq(11).css( 'background-color', 'rgb(153, 255, 153)');
         }
     },
    

    https://datatables.net/reference/option/createdRow

    Shay

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Have you looked at applying CSS class names to columns?
    https://datatables.net/reference/option/columns.className

This discussion has been closed.