is there any example of server side ajax response with more than 1 draw

is there any example of server side ajax response with more than 1 draw

jfrjfr Posts: 71Questions: 24Answers: 0

I am having problem with client datatables when setting "serverSide": true
Datables is looping asking for new data
I must be doiing something wrong on my server side

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30

    See this example and perform any operation - sorting, filtering or page change. That should result in a new request to the server which you can inspect using developer tools in your browser.


    See more articles about jQuery DataTables on gyrocode.com.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Sounds like you might be calling the draw() function in draw or drawCallback perhaps?

    Allan

  • RoshniTrumpRoshniTrump Posts: 1Questions: 0Answers: 0
    edited June 2017

    use the .fail() deferred object to find out your error. See this example of jQuery post where they have used it. If will be helpful for you.

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Actually, you can use error right in your DataTable ajax

    $().DataTable(
    {
        serverSide:true,
        ajax:{
            url: "my path",
            data:function(reqParam) {
              // to see exactly what is being sent
               console.log(reqParam);
               return reqParam;
           },
            dataFilter: function(response){
                // this to see what exactly is being sent back
                console.log(response);
                return response
            },
            error: function(error) {
                // to see what the error is
                 console.log(error);
            }},
            blah blah blah
    }
    );
    
  • jfrjfr Posts: 71Questions: 24Answers: 0

    Thanks all for your response

    I am using to add a class for inactive record

    "drawCallback": function( settings) {
       if (settings.aoData.length > 0) {
          oTable.cells( function ( idx, data, node ) {
            if (jQuery(node).hasClass("statut") && ["0","9"].indexOf(data) == -1 ) {
                row = oTable.row(node._DT_CellIndex.row).node();
                jQuery(row).addClass("statutInactif");
             }
          });
       }
    },
    

    Should I move it esle where ?

    Thanks again

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Using the rowCreated callback will let you do it without accessing any private properties (the settings object and _DT_CellIndex).

    Allan

  • jfrjfr Posts: 71Questions: 24Answers: 0

    Sorry Allan

    but when I click on rowCreated I get a 404 Page not found

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    I think Allan meant to point you to createdRow.

    Kevin

  • jfrjfr Posts: 71Questions: 24Answers: 0

    Hi again
    I have deleted the drawCallback and remove all the draw but still looping

    draw:1
    +++
    order[0][column]:1
    order[0][dir]:asc
    start:0
    length:1200
    search[value]:
    search[regex]:false

    And I return

    {"draw":1, "recordsTotal": 100, "recordsFiltered": 100, "data": [{++

    and then it goes on for draw 2, 3, 4 and so on

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Oops - yes I did. Thanks for the correction Kevin.

    @jfr - we'd really need an example able showing the issue so we can see the code and understand why that might be happening. Something must be triggering a redraw.

    Allan

  • jfrjfr Posts: 71Questions: 24Answers: 0

    Hi Allan

    I have removed oTable.scroller.measure() that was causing the redraw

    thank for your help

This discussion has been closed.