• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

34
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 1 month ago ·

Juan Pablo Isaza

Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.