So my company decided to keep on using datatables, since we already had time invested, and there is a pretty good community for it, etc.
Suddenly, though, our code broke. And we weren't sure why.
I did a lot of javascript debugging. At first it was weird because we were using a property named "length" for a very specific purpose. It was for the function we made for https://datatables.net/reference/option/ajax#function but that page doesn't describe what's in "data", so it took me a while to trust that "length" was the property we really wanted, especially when its current value was showing up as null or even NaN.
(Another lesson learned: Any given "NaN" Not-A-Number value is NOT the same as any other "NaN" value (this is so you don't think 5/0 == 3/0, or something) so about the only way to test for something being NaN is a specialty isNaN() function.) And NaN != undefined, unfortunately.)
Anyway, later in my search I found http://datatables.net/manual/server-side that seemed to confirm, as dumb a property name choice as it is, "length" was what we were looking for.
So, using chrome debugger, I found that that value ultimately derives from _iDisplayLength in jquery.dataTables.js -- I spent too many hours trying to set up breakpoints wherever it might be set, but couldn't find anything... as soon as I saw it, it was already NaN! Frustrating.
At this point, empirically, we realized that our Bower instance had upgraded the "scroller" plug in from 1.2.0 to 1.2.1, and that putting it back would fix the problem.
So I had no idea! Part of the thing is I was looking in /scripts/js/jquery.dataTables.js, while this script that was changing the variables I was desperately hunting for was in /js/lib/bower/datatables-scroller/js/dataTables.scroller.js -- exacerbating it, any variable starting with an underscore is usually considered rather private, but by convention. Not the case with Datatables plugins though, which I knew but kind of forgot. So I forgot to search across .js files, either in my IntelliJ editor, or in chrome (chrome isn't great at doing cross-js file searches though -- see http://stackoverflow.com/questions/4145266/how-to-search-all-loaded-scripts-in-chrome-developer-tools for some info on that)
Not helping things was the snarky response I got from the datatable forums... maybe my own dumb fault for not following the "you must have a test case!" rules they apparently have, but man-- making a simple test case from our pile of angular and Server-side AJAX seemed pretty unlikely. So https://datatables.net/forums/discussion/20839/contents-of-ajax-function-data-param-determining-how-many-records-to-load is another view of that.
Too much complexity, I think, in both the build tools we're using, and the plugins. But we learned some good lessons about locking down version numbers.
No comments:
Post a Comment