Coloring a row depending on a hidden field and an array or db entry.

Coloring a row depending on a hidden field and an array or db entry.

phantom001phantom001 Posts: 2Questions: 0Answers: 0
edited April 2014 in DataTables 1.9
Hello

I am new to DataTabels and absolut no idea how to solve it ... hope some one can help.

I have a hidden field with lets say rose, ocan, sand .... in it.

Then I have entrys in a DB (provided as array) with two colums thing and color.

So one of the records may be rose ---> #FF0000 (red).

I want everytime when the hidden field contains rose that the backround of the row changes to the color #FF0000 or when it contains ocan its change to color #0033FF (blue) and so on.

But i have no idea how to hook in :-(

THANK YOU !

Replies

  • allanallan Posts: 54,914Questions: 1Answers: 8,608 Site admin
    You can use fnCreatedRow or fnCreatedCell to manipulate the elements based on the data.

    Allan
  • phantom001phantom001 Posts: 2Questions: 0Answers: 0

    Hello

    Thx allan for the answer but i didnt get along with it because i get the data from a json Dataset and dont create the table row by row ...

    But after some Time i found a solution and its so simple :-)

    I have just used fnRowCallback

    Example:
    In the if i check if the datafield value matches somthing in this example "10"

    If it match i color the row in this case red with the .css selector , <td> and nRow (the actual row).

    "fnRowCallback":function(nRow, aData) {
    if (aData[4] == "10")
    {
    $('td', nRow).css({"background-color":"red"});
    }
    }

    So i can check if the value matches my color values and coloring the rows.

    Thanks

  • allanallan Posts: 54,914Questions: 1Answers: 8,608 Site admin

    Nice one :-)

    Allan

  • kqueekqueekqueekquee Posts: 40Questions: 1Answers: 0

    thanks it's ok to color a row when a value is null

        // colorie la ligne en rose clair si le centre est vide
        "fnRowCallback": function(nRow, aData) {
          if (aData[5] === "" ) {
            $('td', nRow).css({"background-color": "#F8E0E6"});
          }
        },
    
This discussion has been closed.