I made a lot of these errors myself, so don't feel bad if they happen to you. But learn to recognize them and avoid them.
My program works fine on Chrome and Firefox, but in IE nothing works.
- The trailing comma. In arrays and objects, Chrome and Firefox and now the ECMA specification allow for a trailing comma. IE will crash if you have an extra comma in your arrays or objects. (I've been told IE 9 now fixes this.) a = [1,2,3,];
- console.log(). The console object is not provided by default in IE's Javascript environment so if you're in the habit of adding console.log() debug code you are breaking your app for IE. Sorry.
- Have you run your JSON through the http://jsonlint.com/ validator?
- make sure special characters are 'escaped', i.e. backslashes:
$string_in_json = str_replace('\\', '\\\\', $remarks);
- It's not enough to just provide valid JSON. Your JSON object has to have the right object/layout that DataTables expects. The requirements for the callback in fnServerData are even more important.
- For a valid AJAX source example see http://www.datatables.net/release-datatables/examples/ajax/sources/arrays.txt or the debugger's network panel on when viewing a working example.
- For valid server-side return, make sure to conform to this specification: http://www.datatables.net/usage/server-side
- Make sure your libraries are included in the right order. jquery.js must be included before datatables.js. editable.js is needed before the datatables.editable.js (but after jquery). Feature plugins should usually be included after datatables.js but before you call your .dataTables() function.
- Are you including jquery.js more than once? If you are loading data into another panel (unless it's in an iframe or another window) and you include jquery.js (or other libraries) in that code, you could be clobbering the original jquery code AND the API functions that datatables.js adds to the JQuery object/library.
- Make sure you have a JQuery object, or a DOM object. There are tips in the JQuery basics blog for telling the difference.
- Make sure your variables have been defined and constructed properly.
'k is not defined'.
- Your TABLE element HAS TO have a THEAD element in order for DataTables to work with it.
- You need th same number of columns in the THEAD as you have in your array-source, AJAX-source, or db-source data. Check your sources.
- Is your source valid JSON as well as the correct format for DataTables? (see above)
- outerHTML is not valid Javascript in the spec and not supported on many browsers.
- If you haven't specified an sType, DataTables will try to detect the type. It won't always guess correctly. Use sType if you have issues. Or define a type detector routine and add to your DataTables instance.
- DataTables, by default, only supports a few types like date (SOME date formats, not all), number, string, and a special html type for stripping html before sorting. If you have a $ or currency sign, your currency looks like a string, not a number. If you have commas or field delimiters in your numbers, they look like strings. You can install custom sorting routines and new types for type detection; see http://www.datatables.net/plug-ins/sorting and http://www.datatables.net/development/sorting#type_based
- If you added content (like HTML code) using fnRender or a jEditable change and aren't using bUseRendered = false your sort routines will be affected by the HTML code.
- Ok, this one is not your fault. There was a bug in DataTables up to 1.8.1 that didn't properly detect null in some places. You can upgrade to 1.8.2+ or you can specify sDefaultContent for any column to avoid this error. see http://www.datatables.net/ref#sDefaultContent
- This is not a bug. When using server side processing, all processing is done on the server side. There are ways to make these features work, but they are not DataTables issues.
- The way DataTables works to allow scrolling of table body but not the header is to copy the header and footer to other divs and make the original header and footer { display: none }. If you have items that force the header to display, you can end up with extra headers and footers.
Some great stuff in here, FBas. Here's how I solve the console.log issue while simultaneously "silencing" the occasional noisy alert that DT comes up with:
ReplyDeletehttp://gregpettit.ca/2011/send-javascript-alerts-to-console/
Interesting one. Keep posting such kind of information on your blog. Thanks for the share.
ReplyDeletehtml5 video player