How to add data-attribute in a cell (server-side)
How to add data-attribute in a cell (server-side)

Hello all,
I use datatable with ajax and server-side
How can I add some information in cell (td)?
There is an exemple at http://www.cscc.edu/_resources/app-data/datatables/examples/advanced_init/html5-data-attributes.html
But I need it with server side and specific attribute like data-validated='ok'...
Is there a way to do that?
Thanks in advance
Raphael
This discussion has been closed.
Answers
You would just have to use the
createdRow
And by the way, using
$( row ).find('td:eq(0)').data('key','val');
wont work, you have to use the$().attr()
to set the attributeThank for your answer but it doesn't solve my issue, because the data-attribute is for a td (per cell) and I cannot make a rule to put $().attri() regarding the value of the cell.
Sorry, I find that I did'nt explain enought :
in db, I have :
name | value_1 | validated_3 | value_2 | validated_2 ... value_50 | validated_50
I need a table with name and value_1 to valur_50 and adding a color to the cell value_x if 'validated_x==1'.
So if there any way to had a data-attribute on ajax request, I will need to add the columns without displaying it...:(
Reason of my search about this point, so if any idea..
Can you show me an example of what you expect the HTML within the DOM to look like?
for the moment, with db:
I have :
I need :
PS. \s\s was a markdown issue :)
another way could be with invisible columns:
but I'm lost to to create the attribute with cell.index +1 :(
I cannot edit previous post, so corrected post :
Well my solution would work just fine.. You just add the data-validate attribute via
createdRow
, you can determine the value however you want, but setting it would be just like I said above..Throw the following in your
createdRow
, and view the DOM source, it should be just like you want. thetd:eq(2)
tells it to insert that attribute on the 3rd cellThats how its done.
Great! Thanks a lot
I do
Is there a better way to have the value of td:eq(2)?
Not that I'm aware of, its either that or
$(row).find('td').eq(0)
, same thing though...Heres what I do.
I will try both solutions:
and parsing the table with jquery after loading the table
Will give you feedback...
(thanks again for you help)
No problem bud
..at the end, I use a ajax after loading the table, more simple in my case
thanks for your help
Usually is easier that way..