Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
datatable.net not clearing before reload

I have above code to reload the datatable in DataTable generic react component.

everything works fine. but I want to clear the datatable before every reload. and the datatable.clear().draw() is not working. in case of 422 validation error the old data remain there filled in the datatable.

 window.DatatableBasic = (function () {

    var initDatatable = function () {
      datatable = $('#datatablebasic')
        .DataTable({
          //options...
        })
        

    return {
      // public functions
      init: function () {
        if (!$.fn.DataTable.isDataTable('#datatablebasic')) {
          initDatatable()
        }
      },
      reload: function () {
        // $('#datatablebasic').Datatable().ajax.reload();
        if (datatable && datatable.ajax) {
          //reset pagination on submit searchButton
          // datatable.clear().draw();
          console.log(datatable)
          $('#datatablebasic').dataTable().fnPageChange(0);
          const count = $('#datatablebasic').DataTable().data().count();
          if (count > 1) {
            datatable.ajax.reload(null, false);
          } else {
            datatable.ajax.reload(null, true);
          }
        } else {
          this.reinit();
        }
      },
      reinit: function () {
        if ($.fn.DataTable.isDataTable('#datatablebasic')) {
          $('#datatablebasic').dataTable().fnDestroy()
        }
        initDatatable()
      },
    }
  })()
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!