contents of ajax function data param / determining how many records to load

contents of ajax function data param / determining how many records to load

kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

We are using datatables 1.10 with the scroller.
We have an ajax function that we pass as the ajax: parameter when we start up datatables.
I assume this is the function outlined here: https://datatables.net/reference/option/ajax#function but there the description is "Data to send to the server" ... not very specific!

The person who coded this inspected the object, and it seemed like the "length" property was what he was looking for, in terms of how many records the query should request.

Does that seem right? (.length is also used for array and string sizing, so I'm a little worried about it)

The problem is .length is coming up as null or NaN sometimes, so we are constructing bogus URLs and things are generally failing.

So my other question is: HOW is datatables determining how many rows our query should ask for? I wonder if it might have something to do with the pixel size of the display window? Like its ( (pixel height of window / pixel height of row) * 2) or someting? Why would it fail? Or are we barking up the wrong tree completely? Is this a misconfiguration somewhere?

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited May 2014

    Is this a misconfiguration somewhere?

    Without seeing the code, who knows?

    https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    I would like some insight into what we can expect to be in the "data" parameter as mentioned on https://datatables.net/reference/option/ajax#function and described as "Data to send to the server". Is ".length" considered the property to read, and if so, how is it derived for the case of the DT 1.10 scroller?

    I feel these are questions that fall under " Questions about the capabilities of DataTables / feature requests etc, which do not actually require a working example." In this case I am requesting a supplement to some sparse documentation.

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    http://datatables.net/manual/server-side might be some of what I'm looking for. It's still not clear to me when .length would be NaN or null. I can't send you an isolated example to run, alas, because our datatables code is fairly tightly coupled with an angular wrapper, and nothing works (or fails to work in the same way) in isolation

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    (though in general, I find "length" an unfortunate choice for a property name, given the length is already a property for strings and arrays in javascript)

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    Diving into the code, I see a ._iDisplayLength, that this is at least a temporary key where .length will be taken from -- there are 14 references to it in jquery.dataTables.js , a few of them where it is being set, but I can't isolate where it is being set to NaN -- I'll keep putting in breakpoints, but any insight would be welcome.

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    I'm still not sure if code can help, because the situation involves a live server and a lot of angular. Does seeing our initialize dataTable help?

                $dt = $table.dataTable({
                    columns: getColumns(),
                    order: [8, 'desc'], //default sort
                    rowCallback: modifyRowBeforeDisplay,
                    drawCallback: onDraw,
                    serverSide: true,
                    ajax: $scope.loadServerData,
                    autoWidth: true,
                    dom: "rtS",  
                    pageLength: 50,
                    scrollX: true,
                    scrollY: 600,         
                    scrollCollapse: true, 
                    language: {
                        "sInfo": "Showing _START_ to _END_ out of _TOTAL_ sites",
                        "sInfoEmpty": "No sites found"
                    }
                });
    

    Again, I've put in a ton of break points, before ANY reference to _iDisplayLength -- the first few I don't quite get, but pretty early on, _iDisplayLength is NaN. Could this be a timing issue, like something is trying to read the space before that part of the page is built, or something?

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    Continuing the search:
    We have empirically isolated the problem as happening in the Scroller 1.2.0 to 1.2.1 transition.
    (I guess i didn't realize that a different script would be using direct access to jquery.dataTables.js's _iDisplayLength , to set it... my current guess is something in

    this.s.viewportRows = parseInt( heights.viewport / heights.row, 10 )+1;
    this.s.dt._iDisplayLength = this.s.viewportRows * this.s.displayBuffer;

    is not coming out right, and so set _iDisplayLength to NaN.

    Again, apologies for not quote following the forum guidelines, but I don't have a testcase that works outside of our angular.js world, or without using the JSON dynamically pulled from my server.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    I'm guessing you are using server-side processing - is that correct? If so, the parameters being set to the server are documented in the server-side processing manual page. If you aren't using server-side processing, then by default DataTables doesn't sent any parameters, since it doesn't need to.

    There does appear to be an error with Scroller at the moment, which I'll look at once I've done my daily two hours of morning forum posts. You can see it here: https://datatables.net/extensions/scroller/ (again, I'm assuming you are using Scroller based on your latter comments above). Does that look like the error you are seeing?

    Allan

  • kirkjerkkirkjerk Posts: 23Questions: 5Answers: 0

    As a general suggestion, could there be a link from https://datatables.net/reference/option/ajax#function to http://datatables.net/manual/server-side ?

    The problem looks like it might be similar to what's showing up there, yes, at least in terms of basic functions being broken, and NaN showing up places.

    Again, apologies for not being able to provide a better test case; it's tough once you wrap this in Angular, not to mention with server side processing.

    Thank you for your feedback!

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    could there be a link from https://datatables.net/reference/option/ajax#function to http://datatables.net/manual/server-side ?

    Sounds like a good idea. I'll add that when I get into the office tomorrow.

    I didn't get a chance to look into the Scroller error on my site today, will try to make sure I do tomorrow.

    Allan

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5
    edited May 2014

    Hi, did this get resolved.

    I have just converted over to the 1.10.0 version and I'm using.

    Scroller 1.2.2-dev

    Server side paging.

    If my div container with the DataTable in is hidden with

    style="display:none;

    when the Datatable Js is loaded and then the div container unhidden using $(".Container").removeAttr("style"); the error occurs.

    Ive attempted to add a .draw(); after the unhiding but still the same problem.

    the error is length is passed as NaN

This discussion has been closed.