[solved] set styles on individual cells
[solved] set styles on individual cells
Let me start by saying that I love DataTables! It's made some of my projects VERY nice, especially with the server-side functionality.
What I have is a table being generated from a MySQL data source. Basically I'm displaying rows of website tickets that show multiple steps of completion (header images, building content, etc). I would like to apply a class (or some sort of styling) that sets the color of a cell based on data from the database, but I can't see a good way to pass anything like that along in the JSON string.
I've looked at some of the examples and other posts in the forum and have seen how to do an entire column or a cell based on specific text (making the "A" bold in one of the examples), but some of the text I'm outputting is dynamic so I can't use that method to set the style.
Anybody have any thoughts?
What I have is a table being generated from a MySQL data source. Basically I'm displaying rows of website tickets that show multiple steps of completion (header images, building content, etc). I would like to apply a class (or some sort of styling) that sets the color of a cell based on data from the database, but I can't see a good way to pass anything like that along in the JSON string.
I've looked at some of the examples and other posts in the forum and have seen how to do an entire column or a cell based on specific text (making the "A" bold in one of the examples), but some of the text I'm outputting is dynamic so I can't use that method to set the style.
Anybody have any thoughts?
This discussion has been closed.
Replies
Hth,
Gerardo
Thanks!
You can also use sClass (in the js side of the code). Or use php to output the js code.
If you really want to do it via json, you can add a styles array to the json output (alongside aaData), and reference if using json.styles.
Hth,
Gerardo
My other concern is that if I do it through the js side, I could be outputting a LOT of js to set backgrounds if somebody is displaying 100 rows. I have 6 or 7 columns that get styled and with 100 rows that's a lot of javascript to output. I can do it that way if it's my only option, I was just looking for something a little cleaner.
Is there an example of using the json.styles that you could point me to?
Thanks!
Insead of :
"bla bla"
just return:
"bla bla"
Hope it helps you.
big-deal
[code]$("div.approved").parent().addClass('approved');[/code]
That gave the the class i wanted without having direct access to the table tags.
Thanks for your help, everybody! I'm calling this fixed!