简体   繁体   中英

Datatables with requirejs $(…).DataTable is not a function

I have problem when I load data-tables with requirejs.

Following is my code

require.config({
    paths: {
        "datatables" : "https://cdn.datatables.net/u/dt/jq-2.2.3,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.12,b-1.2.1,b-colvis-1.2.1,b-flash-1.2.1,b-html5-1.2.1,b-print-1.2.1,fc-3.2.2,fh-3.1.2,r-2.1.0,sc-1.4.2,se-1.2.0/datatables.min",
    }
});


requirejs( ["datatables"], function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf'
        ]
    });
});

I have generated datatables.min.js from the following link: https://www.datatables.net/download/

Already included the jquery and other extensions, but I got this error:

$(...).DataTable is not a function

Can anyone help me?

You should use Jquery ready function, for example :

requirejs( ["datatables"], function() {
   $(function(){ // ready function 
     $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf'
        ]
     });
   });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM