Bug with server side processing + deferLoading and columns definition?!

Bug with server side processing + deferLoading and columns definition?!

tinogo89tinogo89 Posts: 3Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
Hello,

I've just discovered a possible bug when using server side processing, deferLoading and using column definitions.
As an Example, just adjust the "Deferred loading of data" as follows:
[code]
$(document).ready(function () {
$('#example').DataTable({
"processing": true,
"serverSide": true,
"ajax": "scripts/objects.php",
"columns": [
{ "data": "first_name" },
{ "data": "last_name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "start_date" },
{ "data": "salary" }
],
"deferLoading": 57
});
});
[/code]

As a result, you will get the following error message:
[quote]
"DataTables warning: table id=example - Requested unknown parameter 'first_name' for row 0. For more information about this error, please see http://datatables.net/tn/4"
[/quote]

Am I missing something or is it a bug?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Have you also modified the HTML to include the rows of data that have been deferred on load? DataTables will read that data from the DOM.

    Allan
  • tinogo89tinogo89 Posts: 3Questions: 0Answers: 0
    edited April 2014
    Hello Allan,

    thank you for your quick reply.
    Yes, the "preloaded" data is present inside the table body.
    Do these table rows/cell need some additional information/attributes, so that DataTables registers them as preloaded data?

    Regards

    Btw: The Server Processing examples on next.datatables.net are currently not working, e.g. http://next.datatables.net/examples/server_side/simple.html .
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > Do these table rows/cell need some additional information/attributes, so that DataTables registers them as preloaded data?

    No they should just work. I've got a feeling that the issue is the use of objects in the data source, rather than arrays, which is how DataTables reads the DOM data. I'm not entirely sure how to address that at the moment...

    > The Server Processing examples on next.datatables.net are currently not working

    Darn - thanks for letting me know about that!

    Allan
  • tinogo89tinogo89 Posts: 3Questions: 0Answers: 0
    Hi Allan,

    okay - so there is currently no other solution, than disabling deferLoading when using column definitions?

    If yes - what do think how long it would take to fix it?

    Regards and keep up the good work!
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    There isn't currently a solution and to be honest I'm not sure how long it would take to fix as I haven't really had a chance to think about it yet.

    The problem is that the DOM source is arrays, and your data is objects - they are completely disparate. Possibly it would need a bypass on reading the DOM data, but that would break things such as column visibility and so on.

    Allan
  • dquimperdquimper Posts: 1Questions: 0Answers: 0
    edited July 2014

    Hi Guys,

    Any update on this issue. Is there a way I can tell datatable to ignore the column.data info until the first server call is made?

    In the mean time, I found that we can use the data option with deferLoading to load the initial data without using the DOM.

    $(document).ready(function () {
      $('#example').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/objects.php",
        "columns": [
          { "data": "first_name" },
          { "data": "last_name" },
          { "data": "position" },
          { "data": "office" },
          { "data": "start_date" },
          { "data": "salary" }
        ],
        "deferLoading": 57,
        "data": [{"first_name": "Henry", "last_name": "Smith", "position": "....... },{...}]
      });
    });
    
  • CoggsflCoggsfl Posts: 6Questions: 0Answers: 0

    I am experiencing the same issue when trying to upgrade from 1.9.4 to 1.10. The deferLoading functionality was working in 1.9.4, but now returns the same error described above ( ...Requested unknown parameter... ).

    My current work around is to deactivate the deferLoading feature.

    Rich

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

    @Coggsfl - and you link to a test case showing the issue please?

    Allan

  • CoggsflCoggsfl Posts: 6Questions: 0Answers: 0

    @allan - here you go : http://debug.datatables.net/agelom

    Thanks
    Rich

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

    Thanks. This is confirmation of my suspicions about the issue being related to using object data from the server, but array data from the first read from the DOM.

    I'm afraid I don't have a fix for this yet, but I will try to work on one soon.

    Allan

  • FajitaNachosFajitaNachos Posts: 3Questions: 1Answers: 0

    Hey Allan,

    Just checking in on the fix. I'm sure you're super busy, but it would be nice to get this one sorted. I'll be happy to give it a try if you have a suggestion on where to start.

    Thanks

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

    Not yet, I've been working on other things. I think the fix for this will be to map the data from the DOM to an object, rather than an array (which is also the subject of another bug, which I thought I had filed on github, but apparently not...).

    The starting point would probably be in this function.

    Allan

  • FajitaNachosFajitaNachos Posts: 3Questions: 1Answers: 0

    Thanks for the update! We actually just switched today from server side back to client side processing. Should we go back, I'll attempt to fix the bug, and submit a pull request.

  • janflorajanflora Posts: 1Questions: 0Answers: 0
    edited September 2014

    You can always parse the DOM data for DataTables like so:

    var columns = [
          { "data": "first_name" },
          { "data": "last_name" },
          { "data": "position" },
          { "data": "office" },
          { "data": "start_date" },
          { "data": "salary" }
    ];
    
    var data = [];
    $('#example tbody tr').each(
        function()
        {
            var item = {};
            $(this).find('td').each(
                function(i)
                {
                    item[columns[i].data] = $(this).html();
                }
            );
            data.push(item);
        }
    );
    
    $('#example').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/objects.php",
        "columns": columns,
        "deferLoading": 57,
        "data": data
    });
    
This discussion has been closed.