Update cell based on unique column value
Update cell based on unique column value
sbarnett
Posts: 23Questions: 5Answers: 0
Hi,
I have a server side script which sends JSON to the JS on the client side. The data contains a unique ID (which maps to a hidden column in the table which has already been drawn). I need this JS to be able to take that unique ID and use the JSON data to update the row specified by the unique ID.
Does that make sense?
How would I go about getting hold of the row I need to update based on the unique column value?
Thanks,
Simon
I have a server side script which sends JSON to the JS on the client side. The data contains a unique ID (which maps to a hidden column in the table which has already been drawn). I need this JS to be able to take that unique ID and use the JSON data to update the row specified by the unique ID.
Does that make sense?
How would I go about getting hold of the row I need to update based on the unique column value?
Thanks,
Simon
This discussion has been closed.
Replies
[code]
var oTable = $('#gridId').dataTable();
var nRows = oTable.fnGetNodes();
for (var i in nRows) {
if (oTable.fnGetData(nRows[i]).id == idYouAreLookingFor)
oTable.fnUpdate(newData, nRows[i])
}
[/code]
Don't spose anyone else has any ideas that might be a bit more optimal?
(Thanks by the way - not putting your suggestion down - I'd just like for there to be a more efficient way)
[code]
var table = $('#tableId').dataTable({
fnRowCallback: function(tr, rowData) {
$(tr).attr(rowData.id);
return tr;
}
});
table.fnUpdate(newData, $('#'+idYouAreLookingFor)[0]);
[/code]
In reality you would probably want to prefix the ids given to each of the rows with something to make sure they don't conflict with any other ids on the page, but that's the basic idea.