Ajax Souce and give individual cells a different class name

Ajax Souce and give individual cells a different class name

mchaneymchaney Posts: 2Questions: 0Answers: 0
edited May 2013 in General
I have my Table working fine and rendering fine by getting the table data from an ajax source absolutely fine. (I have full control over the data that is being generated through PHP and mysql). Quite often the data will consist of blank cells (which I return as empty strings). What I would like to do is to be able to style these using CSS, for example empty cells being coloured dark grey. There will also be spacer columns that need to be a certain width and colour. Does anyone know how you can add classes to the td cells that get generated on an individual basis.

I can calculate what the td class attr should be in the php ajax source calculation, but I can't work out how then to use it.

A simple example:


Text To Display
Text To Display



Where td.empty {background-color:grey} would want to work. and td.data {color:red}.

I could use a span with an id in the returned cell contents from the ajax source, but there are times when I want to change the cell border, widths etc.

Thanks

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    Currently there is no build in way to do this. What you would need to do is use the fnCreatedCell callback to add the class when DataTables creates the cell.

    Allan
  • mchaneymchaney Posts: 2Questions: 0Answers: 0
    Thanks Allan, I will give that a go. Any thoughts on whether or not it would be possible to put in the ability to add classes to cells. Maybe on the return object, each row could have the cell data and cell attributes? Rather than just the cell contents? (An utter guess without looking at the code so apologies if that's completely stupid or is a huge job.).
  • axaraxar Posts: 4Questions: 0Answers: 0
    you can try fnRowCallback and traverse through all the elements in that row and act accordingly?
This discussion has been closed.