Is it possible to connect datatables to Node.js server ? - Page 2

Is it possible to connect datatables to Node.js server ?

2»

Answers

  • jemzjemz Posts: 131Questions: 40Answers: 1
    edited May 2015

    Hi @allan,

    I did not think like that :).Thank you for the idea,Okay I will try this solution.By the way in the early version of my code, before I will change it to serverside.

    dataarray.forEach(function(d){
            
         if ( table.rows('#'+d.DT_RowId).any(d.DT_RowId) ) {
             console.log('already exist cannot be added');
         }else{
             table.row.add(d).draw();
         }
     
     });
    
    

    the logic of serverside in receiving the data by assigning the result to variable. So I can also Assign the result to a variable instead of doing adding rows and checking if it exist. ?. Am I right ?

    Thank you in advance.

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    Yes, use a variable. But with server-side processing you don't use the API, you call a callback function - see the ajax documentation.

  • jemzjemz Posts: 131Questions: 40Answers: 1
    edited May 2015

    HI @allan,

    Just like this example

       $('#example').dataTable( {
      "ajax": function (data, callback, settings) {
        callback(
          JSON.parse( localStorage.getItem('dataTablesData') )
        );
      }
    } );
    
    

    best regards.

    jemz

  • jemzjemz Posts: 131Questions: 40Answers: 1

    HI @allan,

    I am confuse in using the callback here

    var receivedata;
    
    $('#example').dataTable( {
      "ajax": function (data, callback, settings) {
        callback(
          JSON.parse( localStorage.getItem('dataTablesData') )
        );
      }
    } );
    
    
    socke.on('getdata',function(data){
            receivedata = JSON.parse(data);
        
        
    });
    
    
    

    Thank you in advance

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    Yes, you need to trigger the callback from the socket handler on reception of server-side processing data. You could store the callback in a variable for example.

  • jemzjemz Posts: 131Questions: 40Answers: 1

    HI @allan,

    I think I am in big trouble in implementing the serverside using socket.io because I am using node-mysql for my database. and I need to convert your ssp.class to node-mysql.but I need to find way first if there is another solution for this to use the ssp.class

    Thank you in advance

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    I don't have an example I can send you as that isn't code I've written before. I would be happy to put one together for you though - the Quick Support 180 option will cover the work involved.

    Allan

This discussion has been closed.