Hide data in fnRowCallback

Hide data in fnRowCallback

drakula1234drakula1234 Posts: 58Questions: 1Answers: 0
edited April 2012 in General
I am hiding column when I initially display the table and it works like a charm. I have a search filter and when I enter text in the filter I get the all the values I am passing to the datatable. The table displays data from columns (1-5) instead of from (2-5). I am not sure how do I implement this in the fnRowCallback function. I need some help from the experts.

Thanks in advance

Replies

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    I'm afraid I don't quite understand - are you putting the text from the filter into the columns? Can you link to a test case please?

    Allan
  • drakula1234drakula1234 Posts: 58Questions: 1Answers: 0
    edited April 2012
    Thank you very much for the plugin, it made life easier and thanks for the reply.
    For security reasons I cannot give a link to the test case. No, I am not putting any text in the column. This is the code I have
    [code]
    "aoColumnDefs": [{"bVisible": false, "aTargets": [0]}],
    "bAutoWidth": false,
    [/code]

    and I am using text highlight function written by another person in this forum. So I have that in the fnRowCallback function apart from what I pasted below.

    [code]

    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
    $('td:eq(0), td:eq(1), td:eq(2), td:eq(3)', nRow).css("text-align", "left");
    $('td:eq(4)', nRow).css("text-align", "right");
    return nRow;
    [/code]

    After entering text in the filter, it does an ajax call to get the data from the server side. I have put a break point to check if the control comes to the aoColumnDefs after search text has been entered, the control directly goes to the fnRowCallback function. I am not sure if I have done right. Thanks for your time
  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    aoColumnDefs is used only at initialisation time. At the moment in DataTables you can only specify columns are initialisation time - you can't add and remove columns later. If you do need to do that yo would need to destroy the table ( bDestroy ) and recreate it.

    Allan
  • drakula1234drakula1234 Posts: 58Questions: 1Answers: 0
    If I destroy and redraw the table then I will loose the search filter I believe. I might be wrong but any inputs on a work around solution for this ?
  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    Correct - you would loose the configuration. If you have to destroy the table and recreate it you could enable state saving - set the duration to, say, 5 seconds and force a state save just before you destroy the table, and then when you recreate it, the state will be reloaded, including filtering.

    What are you trying to change? If its just the visibility of a column use fnSetColumnVis - much more flexible :-). Most other options could probably be done with a plug-in as well (although in most cases, such plug-ins don't yet exist, but wouldn't be too hard to create).

    Allan
  • drakula1234drakula1234 Posts: 58Questions: 1Answers: 0
    Thank you very much allan for the reply, fnSetColumnVis didn't work either, it is same as aoColumnDefs. However I found a work around for this. I was masking/hiding the first column when a search filter is applied would display all the columns pushing the last column out of view. My work around was to push the first column to last so that after a search I display what I want :)
This discussion has been closed.