Node Server Not Leveraging Server-Side Processing?

Node Server Not Leveraging Server-Side Processing?

aschuettaschuett Posts: 3Questions: 2Answers: 0
edited July 2020 in Free community support

Link to test case:
Internal-only page.

Debugger code (debug.datatables.net):
Attempted to upload, however the server provided HTTP 500 error, possibly because the upload was ~45MB? I've included a screenshot to at least provide some level of detail.

Error messages shown:
No error messages shown.

Description of problem:
I'm running DataTables 1.10.21 client-side and datatables.net-editor-server 1.9.4 server-side. On the client-side, I have serverSide: true and pageLength: 50. With serverSide: false, everything works great (except it's slow because of loading so many rows). With serverSide: true, I can see the ajax request includes data length: 50, but the server replies with all rows in the table (8000+). Initially I was under the assumption that datatables.net-editor-server did not support SSP.

The server-side route is set up as follows:

var allEvent = async function (req,res) {
  let editor = new Editor(DB.knex, 'auditEvents').fields(
    new Field('id')                       .setFormatter( Format.ifEmpty() ).validator( Validate.dbUnique() ),
    new Field('userId')                   .setFormatter( Format.ifEmpty(null) ),
    new Field('objectType')               .setFormatter( Format.ifEmpty(null) ),
    new Field('objectId')                 .setFormatter( Format.ifEmpty(null) ),
    new Field('actionName')               .setFormatter( Format.ifEmpty(null) ),
    new Field('description')              .setFormatter( Format.ifEmpty(null) ),
    new Field('created_at'),
    new Field('updated_at')
  )
  .on('preCreate',function(editor,values){
    editor
      .field( 'id' )
      .setValue( Uuidv4() );
    editor
      .field( 'created_at' )
      .setValue( new Date().toISOString());
  })
  .on('preEdit',function(editor,values){
    editor
      .field( 'updated_at' )
      .setValue( new Date().toISOString());
  });
    await editor.process(req.body);
    res.json(editor.data());

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    Attempted to upload, however the server provided HTTP 500 error, possibly because the upload was ~45MB? I'

    Yup - that would do it!

    Have you set DataTables' Ajax request to be POST?

    e.g.:

    ajax: {
      url: ...,
      type: 'post'
    }
    

    The reason for that is your server-side script is looking for POST data (await editor.process(req.body);), but the DataTables default is a GET request. See also this example, and its matching equivalent in the NodeJS download package.

    Allan

  • aschuettaschuett Posts: 3Questions: 2Answers: 0

    Allan,
    I'm so embarrassed - such a simple fix. Thank you for the quick help! I can confirm after resolving my basic error, everything works perfectly!

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    No worries - I've made that mistake before plenty of times myself. Good to hear it is working for you now.

    Allan

This discussion has been closed.