2

I am trying to render the column header in a datatables cell. So far I am using columnDefs to adjust the contents of a cell, and I wish to add the column header or title:

"columnDefs": [ {
    "targets": [6], "render": function (data, type, column) {
        return '?continent='+column[1]+'?filter='+this.header;
     }
}]

I have been able to return the column header in the console or as an alert: (https://datatables.net/reference/api/column().header())

but not as text in the cell

Fiddle: http://jsfiddle.net/bbLjzspf/3481/ I would like the header of column 1 - Position - to be inserted into the link where I have written Col1header. Result for row 1 would look like: "tom.html?office=Tokyo?filter=Position"

2
  • what exactly u want to show? craete jsfiddle to and add proper datatable code Commented Jun 4, 2018 at 10:39
  • Thanks, added a fiddle Commented Jun 4, 2018 at 14:05

1 Answer 1

2

Here is the solution:

https://codepen.io/creativedev/pen/bKEPNe

This is columnDefs code which i have changed

"columnDefs": [ {
    "targets": [1], 
    "render": function (data, type, row, meta) {
        var title = $('#example').DataTable().columns( meta.col ).header(); 
        var columnName = $(title).html();
        var url = 'tom.html?office='+row[2]+'?filter='+columnName.toLowerCase();
       return '<a href="'+url.trim()+'">'+data+'</a>';
     }
}]

Also, added "deferRender": true, which will render once dataloaded

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I had tried to do this but with no success, working now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.