Render Link Using Two Datatable Columns

Render Link Using Two Datatable Columns

kmcnetkmcnet Posts: 5Questions: 2Answers: 0

Hello everyone and thanks for your help in advance. I am new to DataTable and need to format a link column using the data from two columns, but I am not sure how or if this can be done. I have been playing around with the render function, but don't know what to do next. I have a column called BalanceStatus that has a value of Open, Closed, Or Partial. This column is returned via JSON. I want the BalanceStatus to be the text of the hyperlink. However, I want to be able to create a hyperlink to another page using the database row ID returned in the JSON as the column ID. The ID column should really not be displayed in any fashion. The completed link should look like <a href "mypage.htm?ID=ID">Balance Status</a>. Any help would be appreciated.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,823Questions: 1Answers: 10,129 Site admin
    Answer ✓

    You are correct - the columns.render method should be used. There is an example of how to create a link in the reference documentation for that option.

    You can access the full data for the row as described in the documentation here (i.e. use the third parameter passed in).

    Allan

  • kmcnetkmcnet Posts: 5Questions: 2Answers: 0

    Thanks for the response. I did read the document, but, because of my ignorance of javascript, I am confused with where the objects such as data, type, row, etc. that are passed into the renderer come from. I other words, how do the values for each of these objects get set, since virtually every example uses some of them. Are they native objects within the datatable that get set at the ajax call. or somewhere else?

    Thanks again.

  • allanallan Posts: 61,823Questions: 1Answers: 10,129 Site admin
    Answer ✓

    The data is whatever columns.data is configured to point to in the row's data source object. type is the data type DataTables is requesting and row is whatever the original data object is that you use for each row (typically an array of object).

    Allan

  • kmcnetkmcnet Posts: 5Questions: 2Answers: 0

    Thanks again for the response. That clears things up. Thanks for the help.

This discussion has been closed.