AneeshPutturi
AneeshPutturi

Reputation: 768

How to make column data as hyperlink from another column data in dataTable (JQUERY)

I am trying to make hyper link for particular column in datatables from another column data enter image description here

For example position column should have the hyper link with data from the position column

i have tried, it has hyperlink of position column only

columnDefs: [             
{
                  targets:1,

                        render: function (dataSet, type, row, meta) {

                            if (type === 'display') {
                                dataSet = '<a href="http://localhost/application/org?officeid=' + encodeURIComponent(dataSet) + '">' + dataSet + '</a>';
                            }

                            return dataSet;
                        }
                    }
                ]

Upvotes: 2

Views: 711

Answers (1)

markpsmith
markpsmith

Reputation: 4918

You need to access the row property for this. row represents the entire row of data so you reference it by index:

if (type === 'display') {
      dataSet = '<a href="http://localhost/application/org?officeid=' + row[1] + '">' + dataSet + '</a>';
   }

This assumes that the data in column 1 is the Office Id which I'm not sure that is present in your data, you may have to modify your query to ensure this is returned.

Upvotes: 2

Related Questions