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?

jtbarrettjtbarrett Posts: 3Questions: 2Answers: 0

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

  • kendulinkendulin Posts: 5Questions: 0Answers: 0

    Check the options reference for columns.visible.

    "columns" : [
       {"data": "Name"},
       {"data": "PersonID", "visible": false}
    ]
    

    For the render the full data set is available in the full parameter. See options reference for columns.render for more information.

  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Answer ✓

    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 PersonID in the columns.data option.

    In your code above, where you have ajaxrow you would just use full instead. As the documentation states, the third parameter for the columns.render option when used as a function is the original data object for the row. So full.PersonID will get the data you need.

    Allan

  • jtbarrettjtbarrett Posts: 3Questions: 2Answers: 0

    Allan's solution works best for me, thank you both.

This discussion has been closed.