[SOLVED] DataTables with requirejs problem
[SOLVED] DataTables with requirejs problem
moricio
Posts: 5Questions: 0Answers: 0
I have a problem with new version of DataTable.
All is ok with 1.9.4.
I get "TypeError: $(...).dataTable is not a function" :((
Here's how I use it:
main.js
[code]require.config({
baseUrl: "/medias/js/",
paths: {
"jquery": "//ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.0.min",
// "datatable": "//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min",
"datatable": "//datatables.net/download/build/nightly/jquery.dataTables.js?_=99823af74ba032ba950452c707888b11",
"css": "libs/css.min",
},
shim: {
"datatable": {
deps: ["jquery", "css!/medias/css/dataTable.css"]
}
},
map: {
"*": {
"css": "libs/css"
}
}
});[/code]
And the calling inside php script:
[code]
requirejs(["datatable"], function() {
var oTable= $('#Histo').dataTable({
"bInfo": false,
"bAutoWidth": false,
"bFilter": false,
"aaData": [ <?php echo $aaData; ?>],
"aoColumns": [<?php echo $aoColumns; ?>],
});
});
[/code]
All is ok with 1.9.4.
I get "TypeError: $(...).dataTable is not a function" :((
Here's how I use it:
main.js
[code]require.config({
baseUrl: "/medias/js/",
paths: {
"jquery": "//ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.0.min",
// "datatable": "//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min",
"datatable": "//datatables.net/download/build/nightly/jquery.dataTables.js?_=99823af74ba032ba950452c707888b11",
"css": "libs/css.min",
},
shim: {
"datatable": {
deps: ["jquery", "css!/medias/css/dataTable.css"]
}
},
map: {
"*": {
"css": "libs/css"
}
}
});[/code]
And the calling inside php script:
[code]
requirejs(["datatable"], function() {
var oTable= $('#Histo').dataTable({
"bInfo": false,
"bAutoWidth": false,
"bFilter": false,
"aaData": [ <?php echo $aaData; ?>],
"aoColumns": [<?php echo $aoColumns; ?>],
});
});
[/code]
This discussion has been closed.
Replies
This behaviour matches how jQuery registers itself as a named module and I felt it was that safest way given that the extensions can also be loaded this way.
Allan
Everything works perfectly like that.
I wish to congratulate you, your job is just perfect.