How to update the content of a cell from a row?
How to update the content of a cell from a row?
CyrilF
Posts: 10Questions: 2Answers: 0
Hi,
I would like to update the content of a cell for each rows of my dataTable from a JSON object.
Here is my JS code:
var route = routes.controllers.MachineController.states();
var datatable = $("table[data-provide=datatable]").dataTable.api();
$.ajax(
{
type: route.type,
url: route.url,
dataType: "json",
success: function(states)
{
$.each(states, function(id, states)
{
var cell = datatable.cell("[data-rowId=" + id + "]", ".state");
if (cell != undefined)
cell.data(state);
});
}
});
My HTML looks like:
<table data-provide="datatable">
<!--- Here table head --->
<tr data-rowId="1">
<td>Val1</td>
<td class="state">Val to update</td>
<td>Val3</td>
</tr>
<tr data-rowId="2">
<td>Val1</td>
<td class="state">Val to update</td>
<td>Val3</td>
</tr>
<!--- etc. --->
</table>
Unfortunately it doesn't work and Firebug gives me an error:
TypeError: cell[0] is undefined[Learn More] jquery.dataTables.js:8868:9
This discussion has been closed.
Answers
That looks like it should work. Can you give me a link to a test case showing the issue so I can help to debug it please.
Allan
Hi @CyrilF ,
It looks like your usage of
cell()
isn't correct, that second arg doesn't look like right. We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.Cheers,
Colin