TypeError: $.fn.dataTable.colVis is not a constructor

TypeError: $.fn.dataTable.colVis is not a constructor

jfrjfr Posts: 71Questions: 24Answers: 0
edited November 2014 in ColVis

Hi

I am trying the colvis example for datatables 1.10
and on
new $.fn.dataTable.colVis( table );
I get a
TypeError: $.fn.dataTable.colVis is not a constructor

I check on your web site and I get the same error
Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    Its not - $.fn.dataTable.ColVis is :-)

    Allan

  • jfrjfr Posts: 71Questions: 24Answers: 0
  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    Thanks for the link - that is an error in that specific example. I'll fix that tomorrow morning.

    Allan

  • jfrjfr Posts: 71Questions: 24Answers: 0

    Hi Allan

    I am trying with

    var colvis = new jQuery.fn.dataTable.colVis( oTable );
    

    and I get TypeError: jQuery.fn.dataTable.colVis is not a constructor and fire bug is pointing to new
    I took the example at

    http://datatables.net/release-datatables/extensions/ColVis/examples/new_init.html

    Thanks Again

  • jfrjfr Posts: 71Questions: 24Answers: 0
    edited November 2014

    Hi Allan

    I looked at colvis.js and found that the def is ColVis instead of colVis that I copied from the first url

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    Yes, as I noted in my first reply above, the constructor is $.fn.dataTable.ColVis.

    The example is wrong :-(.

    Allan

  • jfrjfr Posts: 71Questions: 24Answers: 0

    Sorry did not understand it

    I am using jQueryUI and the colVis option are not taken into affect

    jQuery(document).ready(function(){
    oTable = jQuery("#mytable").DataTable( {
        "dom": 'R<"#titrePlaceholder"><"H"lfr>t<"F"ip>',
        "colVis": {
                "buttonText": "Aff./Cacher Col",
                "exclude": [ 11 ],
                "activate": "mouseover",
                "overlayFade": 1000,
                "restore": "Conf.Initale",
                "showAll": "Affiche tout"
        },
        "jQueryUI": true
    });
        var colvis = new jQuery.fn.dataTable.ColVis( oTable );
        jQuery( colvis.button() ).insertAfter('#titrePlaceholder');
    });
    

    Thanks Again

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Correct, as it is not the DataTable that is initialising the ColVis instance - you are doing it manually.

    You want to pass the ColVis options in as the second parameter to the ColVis constructor:

    jQuery(document).ready(function(){
    oTable = jQuery("#mytable").DataTable( {
        "dom": 'R<"#titrePlaceholder"><"H"lfr>t<"F"ip>',
        "jQueryUI": true
    });
        var colvis = new jQuery.fn.dataTable.ColVis( oTable, {
                "buttonText": "Aff./Cacher Col",
                "exclude": [ 11 ],
                "activate": "mouseover",
                "overlayFade": 1000,
                "restore": "Conf.Initale",
                "showAll": "Affiche tout"
        } );
        jQuery( colvis.button() ).insertAfter('#titrePlaceholder');
    });
    

    Allan

  • jfrjfr Posts: 71Questions: 24Answers: 0

    Hi again
    I have seen the ColVis category selection on the right
    Should been the before asking
    Thanks again

This discussion has been closed.