DataTables / TableTools

Please note that TableTools has now been retired and replaced by the Buttons and Select extensions which offers significant improvements and API integration with the rest of DataTables and the other extensions.
http://datatables.net/
Other
237 stars 149 forks source link

Test if jQuery and dataTables is loaded #77

Closed Mechazawa closed 9 years ago

Mechazawa commented 9 years ago

This makes sure that JIT debuggers like visual studio don't throw a hissfit and that the developer is notified about the issue when checking their console.

DataTables commented 9 years ago

Interesting. It is a plug-in for DataTables, which itself depends upon jQuery, so yes those two libraries are required and more or less expected to be on the page. I can see that it might be useful for the odd case when getting started with the libraries but I'm reluctant to include such code in the production versions of the libraries since its just extra code weight that would never be used by the end user. Also if it were done this way here it should also be done like this in DataTables core and all of the other extensions.

Let me have a bit of a think about this!

Mechazawa commented 9 years ago

It's understandable that it's expected that both jquery and DataTables are loaded when the user adds the extension code to their page. But I've found that for things like MVC projects this could not always be the case due to things like the header not always containing the same scripts etc. This will also warn the developer if the scripts are not inserted in the right order ofcourse TableTools => jQuery => DataTables. It's not a major thing at all but it's useful when trying to figure out why the plugin isn't working.

For me this issue came up because another developer was conditionally including DataTables but always including TableTools on certain pages. This made the JIT debugger freak out saying that $.fn.jQuery.fn.dataTable is undefined in the middle of the script.

DataTables commented 9 years ago

Sounds like the Javascript runtime is doing the right thing!

One option might be to investigate if closure compiler can conditionally remove code from the min version. So the non-minified version would contain a little bit of extra sanity checking like this, but the min version, used for production, wouldn't. I'll certainly look into it. Thanks for the feedback.

Mechazawa commented 9 years ago

You can close the pull request if you want so that you can look into adding this and removing it in prod using the closure compiler some other time. Again it's not a major thing just a minor useful thing when developing.