0

I'm trying to reload the ajax data into my Datatables list.

The jQuery code in js file is the following ( semplified )

 "use strict";
 var KTDatatablesDataSourceAjaxServer = function() {

    var initTable1 = function() {
       var table = $('#kt_table_1');

       // begin first table
       table.DataTable({
           responsive: true,
           searchDelay: 500,
           processing: true,
           serverSide: true,
           ajax: server_url,
       });
   };

   return {

       //main function to initiate the module
       init: function() {
           initTable1();
       },

   };

 }();

 jQuery(document).ready(function() {
     KTDatatablesDataSourceAjaxServer.init();
 });

Usually, Datatable API provide the following code to reload the server data

table.ajax.reload(null,false);

But in my case the code above doesn't work...I get an error of table not defined. Any hint to fix the issue?

Thanks a lot

1 Answer 1

2

In this line var table = $('#kt_table_1'); you are declaring table as a reference to DOM object only, not DataTable. Remove this line and Change your table initialization as below:

var table = $('#kt_table_1').DataTable({
           responsive: true,
           searchDelay: 500,
           processing: true,
           serverSide: true,
           ajax: server_url,
       });

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.