Can i make function to reload datatable

Can i make function to reload datatable

ivanjuliantivanjuliant Posts: 4Questions: 1Answers: 0

Hi, I'm new

I make some program with datatable,
When i want try to input data, after process insert data automatically reload table
Here is my example code :

function dataTableCall(NameData){
if(NameData == "kategori"){
var table = $('#table_control').DataTable({
"ajax": BaseURLBack() + '/data/table_' + NameData + '.php?NAMEDATA=' + NameData,
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": false,
"autoWidth": true,
"columnDefs": [
{
"targets": -1,
"data": null,
"render": function ( data, type, full, meta ) {
var FirstButton = '<a href=\'' + data[ 2 ] + '\' class=\'btn btn-info btn-sm ripple-effect\' style=\'margin-bottom:5px;\' data-toggle=\'modal\' data-target=\'#EditModal\'><i class=\'fa fa-pencil\'></i>  Edit</a>';
var SecondButton = '<a href=\'' + data[ 3 ] + '\' class=\'btn btn-danger btn-sm ripple-effect\' style=\'margin-bottom:5px;\' data-toggle=\'modal\' data-target=\'#DeleteModal\'><i class=\'fa fa-pencil\'></i>  Hapus</a>';
return FirstButton + ' ' + SecondButton;
}
}
],
"language": {
"processing": "

"
},
"processing": true
});
}
}

function ReloadDataTable(){
table.ajax.reload();
}

i try to calling ReloadDataTable() , but function not work.
How to fix this ?
Thanks

Replies

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    ReloadDataTable probably doesn't have access to the variable table. Try: $('#table_control').DataTable().ajax.reload();.

    Allan

  • ivanjuliantivanjuliant Posts: 4Questions: 1Answers: 0
    edited November 2016

    OMG thanks allan, you safe my life >_<
    That's work for me.

    THANKS YOU SO MUCH ...

This discussion has been closed.