How do I get a value from source without making it a column?
How do I get a value from source without making it a column?
I have a table of users and I have column (Name) that I wish to render as a link, but only when the row is displaying the currently logged in user. This means that the Person ID for the row source needs to equal the Person ID from session variables.
I know I can make PersonID a column like so:
"columns" : [
{"data": "PersonID"},
{"data": "Name"}
]
I only wish to extract the value for comparison though, like the following pseudo code.
"columns" : [
{"data": "Name"
"render": function (data, type, full, meta) {
If(Session.personID = ajaxrow.PersonID){
return ("<a href="some hyperlink">" + data + "</a>");
}
}
]
Is there a way to get this "ajaxrow.PersonID" without showing it in the table?
This question has an accepted answers - jump to answer
Answers
Check the options reference for columns.visible.
For the render the full data set is available in the full parameter. See options reference for columns.render for more information.
You don't actually need to even have it as a hidden column. Assuming you are loading the data by Ajax, just simply con't create a column that references the
PersonIDin thecolumns.dataoption.In your code above, where you have
ajaxrowyou would just usefullinstead. As the documentation states, the third parameter for thecolumns.renderoption when used as a function is the original data object for the row. Sofull.PersonIDwill get the data you need.Allan
Allan's solution works best for me, thank you both.