I'm using the jQuery Datatables plugin to enable pagination, sorting and searching with my tables. The elements are showing up but not working, and the pagination only sometimes shows up. In Chrome console I'm getting the error:
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in
I'm using Bootstrap alongside this plugin.
No need to downgrade jQuery. I solved the same error by using
aoColumns
asI am using
jQuery 2.1.4
andDataTables 1.10.9
Whilst unrelated to DataTables, I came across this "cannot use in operator to search for length" error. This was the main Google result for the error so just wanted to post my issue as a response in case it helps anyone else.
I had:
I'd forgotten to wrap my selector with the
$
so the fix was to make sure I was passing the actual jQuery elements as the first argument tomap
and not just a string...I'm almost embarrased to post this ;)
Cheers
That error is because of the method
isArraylike
in jQuery version 1.11.3. (only). The method looks like thisThat version of jQuery was using "length" in object to get the length. (I do not know anything about it).
But I do know that no other versions of jquery have that issue.
The versions 1.11.3 and 2.1.4 (as James pointed out in the comments) have this issue.
So the solution would be to just upgrade to the next version or at least use any other version apart from 1.11.3 or 2.1.4
Upgrading to DataTables to DataTables
1.10.7
or1.10.8-dev
did not work for me (using jQuery1.11.3
).Downgrading to jQuery
1.11.2
did work (using DataTables10.0.0
)I had this exact same issue but jQuery version was not the culprit for me. In my case, I was incorrectly serializing the form. The code ended up with this error was:
Whereas I should have used.
I did this and my issue was resolved.
Just throwing out this little piece that I ignored. Could help someone out there.
With DataTables and calling a PHP-script with AJAX, be aware that you just must echo your array at the end. There is no need of encoding it first to a JSON object with json_encode.
So
Otherwise you might end up with the dreadful error
or this one