How do I pass options to ColVis when initialised with new?

How do I pass options to ColVis when initialised with new?

billhailsbillhails Posts: 5Questions: 1Answers: 0

Hi, I'm new around here, and just started integrating ColVis into our site last night.
Although I'm not blocked by this, I'd like to know for future reference. I'm using jQueryUI styling, so I'm following the recommendation to initialise ColVis seperately.
I have:

var table = jQuery('#rhac-re-results-table').DataTable(
    {
        "columnDefs": [
            { "orderable": false, "targets": 8 }
        ],
        ColVis: {
            exclude: [8]
        }
    }
);
var colvis = new jQuery.fn.dataTable.ColVis( table );
jQuery('#rhac-re-results-table_length').css('width', 'auto');
jQuery('#rhac-re-results-table_filter').css('width', 'auto');
jQuery( colvis.button() ).insertAfter('#rhac-re-results-table_filter').css({ 'float': 'right', 'margin-right': '1em' });

As you can see I've tried adding a ColVis attribute to the DataTable argument object, but it doesn't seem to get passed to ColVis, and there doesn't seem to be an options() or similar method that I can call.

This question has an accepted answers - jump to answer

Answers

  • jfbouzanjfbouzan Posts: 4Questions: 0Answers: 0

    I had the same problem. I'm still on legacy versionDatatables 1.9.4 ColVis 1.0.8. But this works for me...

        var colvis = new ColVis( oTable.fnSettings());
          
        document.getElementById('buttonInsert').appendChild(colvis.dom.wrapper);
        colvis.fnRebuild();
    
    
  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Answer ✓

    Second parameter for the ColVis constructor. It takes exactly the same options as the colVis option in DataTables.

    Allan

  • billhailsbillhails Posts: 5Questions: 1Answers: 0

    perfect, thanks to you both.

This discussion has been closed.