Columns.Render - Accessing data for more than 1 column in the render function
Columns.Render - Accessing data for more than 1 column in the render function
Hi all,
I am using datatables with server side rendering and my render function is as follows for a column in my table :
{
"data": "Errors",
"width": "5%",
"orderable": false,
"render":
function (data, type, row) {
var myUrl = '@Url.Action("Foo", "Bar")/' + data;
return '<a href=\"' + myUrl + '\">'+data+'</a>';
}
}
What I need to do is display the value for the data (which is the errors colum) in my link but pass the value of another column (id) as the parameter when the url is clicked. So for the line var myUrl = '@Url.Action("Foo", "Bar")/' + data;
I would like to pass the value of the 'Id' column as data. Is there any way to do this ?
Thanks
This question has accepted answers - jump to:
Answers
I managed to solve this by doing the following :
I'm passing Id as before whilst using the row.Errors parameter of the row object to display the literal value of errors.
Thanks to all who read the post and attempted to help.
You are correct - as the
columns.render
documentation notes, the third parameter passed into the rendering function contains the data for the whole row and you can access it form there.Allan
But the third parameter only contains the data pre-rendering, correct? What if I want to use the output for the render function for another column?
Correct. There is no option to get the rendered data from another column in a rendering function. You'd effectively need to rerender it again.
Allan