How to reload KTDatatable with new parameters?

6k Views Asked by At

I am using KtDatatable for my datatable i have problem when I want to reload my table with new parameters. Usually in regular datatable we used this

'data': function(d) {
     d.date_range = getDaterange();
     d.payment_status = getPaymentStatus();
 }

but in KTDatatable I cant used that, so i used this

params: {
           query: {
                  generalSearch: 'tes',
                  date_range: getDaterange()

           },
         },

The problem is when I call

datatable.reload()

in KTDatatable, it wont get my new parameters with getDaterange() function

I also use this like in regular datatable

datatable.api().ajax.reload();

But it show error .api is not function. How can i send new parameters to my api when reload the datatable ? Thankyou

4

There are 4 best solutions below

0
On BEST ANSWER
params: {
       query: {
              generalSearch: 'tes',
              date_range: getDaterange()

       },
     }

this will only send the initial value of getDaterange()

try this code

params: {
       query: {
              generalSearch: 'tes',
              date_range: function(){
                 return getDaterange();
              }

       },
     }
0
On

datatable.search("value colum", 'name colum');

or if you want to see the applicable functions and objects console.log(datatable);

0
On

try this function datatable.setDataSourceParam(param, value)

https://keenthemes.com/metronic/?page=docs&section=html/components/datatable

0
On

I know the question is more than 1 year old but here is the solution that worked for me today November 9, 2021:

It worked for me to destroy the table and then re-initialize it sending the new data so first I do this:

$('#kt_datatatable').KTDatatatable('destroy');

Then I start the table

KTDatatableChildDataLocalDemo.init(jsonData);

You could also try to reload the table:

$('#kt_datatatable').KTDatatatable('reload');