ColVis - Fire an event

ColVis - Fire an event

DDanyDDany Posts: 6Questions: 0Answers: 0
edited May 2012 in Plug-ins
Hi,
I'm using DataTables with the colVis plugin, I really like both!
I read the documentation, but I think I missed something: I'd like to do execute something when the element that permits to choose columns (.ColVis_collection) disappear, but I'm not able to do this.
Alternatively, I could execute my code when a column is select/deselected, but I prefer the first alternative.

Does anyone have any hint?
Thanks in advance to anyone who will answer,
bye!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    There currently isn't an event fired for when the columns are shown / hidden - or indeed when the ColVis menu is shown / hidden, but both sound like excellent ideas. I've added them to my to-do list.

    At the moment the way to do this would be:

    1. Edit the code to fire the event you want
    2. Use fnDrawCallback and count the number of visible columns to see when the visible column count has changed and then apply your custom function.

    Allan
  • DDanyDDany Posts: 6Questions: 0Answers: 0
    Hi allan,
    first thank for your answer, I'm happy you added those things to your to do list! :)
    Second I used what you suggested me, but there is something strange:
    when I select/deselect a column, the event is called just once, as it should be, but when the table is drawn for the first the event is called twice. Is this the right behavior?

    For the record, I'm using DataTables 1.9.1 and ColVis 1.0.7.
    My dataTables element is configured like this:

    [code]
    var table_acct = $('#display').dataTable({
    "oLanguage":{
    "sShowAll": "Show all",
    "sSearch": "Search" ,
    "sZeroRecords":"No records:"
    },
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": true,
    "bSort": false,
    "bInfo": false,
    "bAutoWidth": false,
    "bStateSave": true,
    "iCookieDuration": 604800,
    "sScrollX": "100%",
    "sScrollXInner": "150%",
    "bScrollCollapse": true,
    "sDom": 'C<"clear">lfrtip',
    "oColVis": {
    "aiExclude": [ 0 ],
    "buttonText":"Show or hide"
    },
    "aoColumns":[ {"bSearchable": true}, {"bSearchable": false},{"bSearchable": false},{"bSearchable": false},
    {"bSearchable": false},{"bSearchable": false},{"bSearchable": false},{"bSearchable": false},
    {"bSearchable": false},{"bSearchable": false},{"bSearchable": false},{"bSearchable": false},
    {"bSearchable": false},{"bSearchable": false},{"bSearchable": false} ],
    "fnDrawCallback": function(){
    console.log("redraw");
    }
    });
    new FixedColumns(table_acct,{iLeftColumns:1, "iLeftWidth": 160});
    [/code]

    Did I do something wrong?

    Bye
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You mean you get the console.log message twice? FixedColumns does a redraw on initialisation (unfortunately this is required to get everything aligned correctly) which will be where the second event is coming from.

    Allan
  • DDanyDDany Posts: 6Questions: 0Answers: 0
    Yes, that's exactly what I meant.
    I'll try to find something to avoid the double call.
    Maybe, as my table is filled with data obtained with an ajax call, I should use the approppriate datasource, even if I use the data obtained to other purposes too. :)
    I'll try to find a way to do this.

    Thanks allan.
This discussion has been closed.