2

In my Datatables, I have used bVisible : false property to hide column. But I want to get data from all columns whether it is hidden or not on click event in jQuery. How can I get all hidden column data?

This is the way I have hidden 5th column:

$('#abc').dataTable( {
    "bDestroy": true,
    "aaSorting" :[],
    "bAutoWidth": false,
    "aoColumns": [ null,null,{ "sType": "numeric-comma" },null,{"bVisible": false},null,null,null,null,null,null,null,null ] 
});

I am getting value of that column using this code:

$(this).closest('tr').find("#xyz").text();

Here xyz is required column td id.

6
  • Define "get data from all columns". Get how? You mean you can search them all? Commented Apr 18, 2016 at 11:37
  • I want to fetch data from all columns and want to display in popup modal on click event.I have tried but not getting hidden column data. Commented Apr 18, 2016 at 11:40
  • Can you add the code you have tried to the question? Commented Apr 18, 2016 at 11:40
  • This is the way I have hidden 5th column :$('#abc').dataTable( { "bDestroy": true, "aaSorting" :[], "bAutoWidth": false, "aoColumns": [ null,null,{ "sType": "numeric-comma" },null,{"bVisible": false},null,null,null,null,null,null,null,null ] }); Now I am getting value of that column using this code : $(this).closest('tr').find("#xyz").text(); here xyz is required column td id. Commented Apr 18, 2016 at 11:45
  • it is like <td id="xyz">. This column is hidden and I am trying to get that column value. Commented Apr 18, 2016 at 12:04

1 Answer 1

0

depending on the version of Datatables you're using...

< 1.9 (ish)

var table = $('#abc').dataTable(dtoptions);

$('#abc').on('click', '.someclicktarget', function(ev) {
  //need the ELEMENT, the the jquery object
  var row = $(this).closest('tr').get(0);

  var data = table.fnGetData(row);

  doSomethingWith(data[indexOfHiddenColumn]);
});

> 1.9.4 (ish)

var table = $('#abc').DataTable(dtoptions);

table.on('click', '.someclicktarget', function(ev) {
  //>=1.10 can operate on either jquery objects OR plain elements
  var row = $(this).closest('tr');

  var data = table.row(row).data();

  doSomethingWith(data[indexOfHiddenColumn]);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for reply. Here indexOfHiddenColumn means at which position column is added to table. I mean 0,1,2 etc. If this is true then is there any other options without giving index of column hard coded.because index will be changed if I add any new column in table.
Yeah, your page logic will need to deal with that complexity if necessary. This is just meant to be a simple example to demonstrate how the DataTables API works. Integrating it with your application is beyond the scope of answers on Stack Overflow.

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.