ServerSide processing using node as backend

ServerSide processing using node as backend

joysonjoyson Posts: 22Questions: 5Answers: 0
edited October 2014 in Free community support

Hi,

Everyone loves Datatables and I am one of them. I saw some discussions for server side processing but all use php. My backend is node. Somehow I am not able to get serverSide to work, it gets stuck. When I remove server side, It takes a long time to load even 10000 records. My boss wants me to load millions of rows in seconds. My code works fine and the only problem that I have is speed. Please help me with this and let me know if you need anything more from me.

Here is my code:

front end jquery:

$(document).ready(function(){

    table = $('#table').DataTable( {
          "serverSide":true,
          "ajax": {
              url:"/users",
              type: "post",
              dataType: 'json'
          },
          "columns": [
              //all my columns.
          ],
          "dom": "'" + dom + "'", //get the dom from the back end according to the privileges to the users
          "order": [[ 3, "desc" ]],
          "scrollX": 1000,
          "scrollY": 292,
          "deferRender": true,
          "ordering": true,
          "processing":true,
          "scrollCollapse": true,
          "scroller": {
            "loadingIndicator": true
          },
          "colVis": {
                  showAll: "Show All",
                  showNone: "Show None"
                }
      });
      //colourizeRows();
      refreshPageButtonCalled();
      return;
  });

backend ajax call:

router.post('/users',function(req,res){

res.setHeader('Content-Type', 'application/json');

var strQuery = "select * from table"; //dummy query as I cannot disclose the actual query.

//console.log(strQuery);

connection.query( strQuery , function(err, rows){

if(err)

{

console.log(err);

}

else

{

// big JSON

var json = {"type": true,"draw": 50,"recordsTotal": rows.length,"recordsFiltered":rows.length,
"data": rows};

res.json(json);

}
}
)
});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    If that is all of your backend code, then it looks like it is missing in the entirety the handling of the server-side processing request. See the manual for what DataTables expects the server-side to implement.

    Allan

  • joysonjoyson Posts: 22Questions: 5Answers: 0

    Hi allan,

    I am new to node and do not exactly know how to do this. Can you give me a start for this. I found this link (https://github.com/jpravetz/node-datatable) but it is from an old version of datatables. I would really appreciate if you could give me an example in node for this.

    Joyson.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Sorry, I don't have an example of using DataTables with Node that I can send you. I'd be happy to provide you with a freelance quote for the work involved in creating an example if you like though.

    Allan

  • joysonjoyson Posts: 22Questions: 5Answers: 0

    Hi allan you can send it to me on my email. I will get approval from the management and let you know. My email is joyson17@gmail.com

    Regards,
    Joyson

  • joysonjoyson Posts: 22Questions: 5Answers: 0

    Hi allan,

    I got it working with the link that I had sent to you in my previous post. I can send you the code if you need it for reference. I still have some changes to make which are for the companies requirement.

    Regards,
    Joyson.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Hi Joyson,

    Sorry I didn't manage to reply to you yesterday, I was just about to this morning but good to hear that you've got it working now. Perhaps a pull request to the repo you linked to might be welcomed by its author.

    Allan

This discussion has been closed.