Setting a new value to a Rendered cell
Setting a new value to a Rendered cell

Hi. I'm trying to create a function that updates a single cell value in existing initialized DataTables.
The below function works if used on a non-rendered column, but on rendered column it will not work.
function updateLastAction(personId, action, actionData = "") {
var table = $('#app-searchresults').DataTable();
let rowId = table.row('#' + personId);
let rowindex = rowId.index();
console.log(actionData);
if (actionData != "") {
//Free comment
console.log(actionData);
var inner = '<span title="' + actionData + '">' + action + '</span>'
table.cell({ row: rowindex, column: 10 }).data(inner).draw();
} else {
table.cell({ row: rowindex, column: 10 }).data(action).draw();
}
}
Here's the column's definition:
{
data: null,
name:'last_actions',
'render': function (data, type, full, meta) {
// Combine last action and comment to single row
var action = ""
var comment = ""
if (data.person_last_action != null) {action = data.person_last_action}
if (data.person_last_action_comment != null) {comment = data.person_last_action_comment}
return '<span title="' + comment + '">' + action + '</span>';
},
},
I'm at my wits end..
So the question is: How to update value to a rendered column? I've tried searching the API and forums, but can't seem to find a match. I was trying things like cell.data([{"data:person_last_action": "TEST","data:person_last_action_comment": "TEST2"}]).draw();
, but nothing seemed to stick..
This question has an accepted answers - jump to answer
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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
Hi, thanks for a swift response!
Here's an example of what I'm trying to do.
http://live.datatables.net/kuzovaba/1/edit
Data on normal cell -button works
Data on rendered cell -button does not work.
Looks like the rendered column gets its data from other data points, ie
data.person_last_action
, in the row. Update those data objects then when drawing the table the render function should run and update.Kevin
Hi kthorngren! Thanks for the response.
I suspected this was the case... but I have no idea how to do this (you can see me pondering this in the end of the starting post, hehe...)
Any pointers?
Your "if" statement needs work.
Are they if/else, if/and, if/or...? And don't you need more than one return point?
@kthorngren thanks for setting me on the right path.
http://live.datatables.net/fuzowute/1/edit
Seems to work fine, though it might not be perfect. Works for me now.
Thank you so much! Marking your reply as answer and leaving the link for others to find here.