• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

180
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()
      },
    }
  })()
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error