Get show/hidden column name

Get show/hidden column name

MiscMisc Posts: 4Questions: 0Answers: 0
edited March 2012 in General
Hi, first i want to thanks you for the great work you did on Datatable.
I'm quite new with this plug-in and I have a little problem with ColVis.

I can retrieve the data using [code]oTable._('tr', {"filter": "applied"});[/code] but but is there any way to get the column name visible in the th elements?

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Currently no - there is not pre-built API for this. You would need to access the fnSettings().aoColumns[].sName parameter for the columns. This could readily be wrapped up into a plug-in API method: http://datatables.net/development/api

    Allan
  • MiscMisc Posts: 4Questions: 0Answers: 0
    Thanks you for your quick answer I will try this =).
  • MiscMisc Posts: 4Questions: 0Answers: 0
    I try some of the code I found on the forums but it seems it didn't work with me (I've probably forgot a few things -_-).
    Here the code i've try with the html example given in the download part.
    [code]
    $(document).ready(function() {
    var oTable = $('#example').dataTable({
    "sDom": 'C<"clear">lfrtip',
    "aoColumns": [
    { "sName": "engine" },
    { "sName": "browser" },
    { "sName": "platform" },
    { "sName": "version" },
    { "sName": "grade" }
    ]
    } );
    ColumnsShown = $('#example').getColumnsShown(this);
    alert(ColumsShown);
    } );
    $.fn.getColumnsShown = function(dTable){
    var vCols = [];
    $.each(dTable.fnSettings().aoColumns, function(c){
    if(dTable.fnSettings().aoColumns[c].bVisible === true){
    vCols = vCols.concat(dTable.fnSettings().aoColumns[c].sName);
    }
    });
    return vCols;
    };
    [/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    That basically looks okay to me - what happens when you run it? I think you want to pass in "oTable" rather than "this" into getColumnsShown btw.

    Allan
  • MiscMisc Posts: 4Questions: 0Answers: 0
    OK, find it ...
    [code]ColumnsShown = $('#example').getColumnsShown(oTable);
    alert(ColumnsShown);[/code]
    forgot the n ...
    Thanks for your answers it' works =).
    Now I'm looking on listeners for filtering and hiding columns (Colvis); I want to recover those data when any columns are filtered or hidden, any tips?
This discussion has been closed.