Trouble optimizing Datatables with DT_bootstrap.js or any datatables plugin
Trouble optimizing Datatables with DT_bootstrap.js or any datatables plugin
I was curious if anyone else has run into a similar situation. I'm currently implementing an application that's making use of jquery.dataTables.js, DT_bootstrap.js, and dataTables.fnReloadAjax. Everything was great until I ran my optimizer to combine everything into one js file, at which point Datatables started exploding. Backing up, I simply made one js file with the 3 datatables js files concatenated into one and it looks like none of the $.fn.DataTable objects are available when code is appended to jquery.dataTables.js. That this only seems to work when they're included as separate files, which seems odd to me.
For reference here are the errors I'm seeing
[code]
// .... end of jquery.dataTables.js
// jQuery aliases
$.fn.DataTable = DataTable;
$.fn.dataTable = DataTable;
$.fn.dataTableSettings = DataTable.settings;
$.fn.dataTableExt = DataTable.ext;
}));
}(window, document));
// ... begining of DT_bootstrap.js
/* Set the defaults for DataTables initialisation */
$.extend( true, $.fn.dataTable.defaults, {
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
}
} );
[/code]
which produces the error
[code]
TypeError: Cannot read property 'defaults' of undefined
[/code]
For reference here are the errors I'm seeing
[code]
// .... end of jquery.dataTables.js
// jQuery aliases
$.fn.DataTable = DataTable;
$.fn.dataTable = DataTable;
$.fn.dataTableSettings = DataTable.settings;
$.fn.dataTableExt = DataTable.ext;
}));
}(window, document));
// ... begining of DT_bootstrap.js
/* Set the defaults for DataTables initialisation */
$.extend( true, $.fn.dataTable.defaults, {
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
}
} );
[/code]
which produces the error
[code]
TypeError: Cannot read property 'defaults' of undefined
[/code]
This discussion has been closed.
Replies
[code]
, function(a) {
return typeof a == "string" && a.indexOf("<") != -1 && a.indexOf(">") != -1 ? "html" : null;
} ]), $.fn.DataTable = DataTable, $.fn.dataTable = DataTable, $.fn.dataTableSettings = DataTable.settings, $.fn.dataTableExt = DataTable.ext;
});
}(window, document)/* end of datatables.min.js start of fnReloadAjax */ , $.fn.dataTableExt.oApi.fnReloadAjax = function(a, b, c, d) {
typeof b != "undefined" && b != null && (a.sAjaxSource = b);
[/code]
which throws
[code]
Uncaught TypeError: Cannot read property 'oApi' of undefined
[/code]
Allan
$.fn.DataTable = DataTable;
$.fn.dataTable = DataTable;
$.fn.dataTableSettings = DataTable.settings;
$.fn.dataTableExt = DataTable.ext;
I ended up just merging the code I needed into jquery.datatables.js which wasn't preferable, but it was the only way I could make it work and run through the optimizer properly.