can we give different color to particular rows out of some rows

can we give different color to particular rows out of some rows

SandeepMSandeepM Posts: 28Questions: 0Answers: 0
edited May 2013 in General
Suppose I have table 0f 10 rows and I want to give different color to 5 rows then what should i do

Replies

  • dimanchedimanche Posts: 3Questions: 0Answers: 0
    It depends on how the five rows are selected. You can define the fnRowCallback function to do something with your row. For example, if you want to set the background-color for rows with a value of 5 in the second column to red, you would use the following code:

    [code]
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    if (aData[1] == 5) {
    $('td', nRow).css('background-color', 'red');
    }
    }
    [/code]
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    It is also worth noting that Server-size processing allows you to set a row-level classname (as well as row-level id), so your back-end server can select which rows should be marked.

    http://datatables.net/release-datatables/examples/server_side/ids.html

    Using this mechanism and some css you can have selected rows highlighted. In the example on this link, rows are colored differently to indicate the 'CSS Grade' column (sort by platform to get a good mix of different grades on the first page).

    the "grade" classes are specified in http://datatables.net/release-datatables/media/css/demo_table.css (it's worth noting that each grade in this example has a slightly different color depending on if it is an even or odd row)
    [code]
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * DataTables row classes
    */
    table.display tr.odd.gradeA {
    background-color: #ddffdd;
    }

    table.display tr.even.gradeA {
    background-color: #eeffee;
    }

    table.display tr.odd.gradeC {
    background-color: #ddddff;
    }

    table.display tr.even.gradeC {
    background-color: #eeeeff;
    }

    table.display tr.odd.gradeX {
    background-color: #ffdddd;
    }

    table.display tr.even.gradeX {
    background-color: #ffeeee;
    }

    table.display tr.odd.gradeU {
    background-color: #ddd;
    }

    table.display tr.even.gradeU {
    background-color: #eee;
    }[/code]
This discussion has been closed.