I would like the Datatable to don't start immediately, the btnInit is to Init the Datatable then after that the btnSearch is to reload for searching, but the btnSearch is not working because the var table is still inside the btnInit, is there a way that after i Init the Datatable i can reload the var table, maybe something like after i Init the var table goes outside the btnInit so the btnSearch can call the var table, please help.
$('#btnInit').on("click", function () {
$("#btnInit").hide();
$("#btnSearch").show();
var table = $('#IPSCICODatatable').DataTable({
"processing": true,
dom: "<'row'<'col-sm-6'l><'col-sm-6'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-2'i><'col-sm-5'B><'col-sm-5'p>>",
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5',
'print'
],
"ajax": {
"url": '/Home/GetAllCICO',
"type": "POST",
"datatype": "json",
"data": function (d) {
d.searchParameters = {};
d.searchParameters.TransCode = $('#txtSSNTIN').val();
}
},
"columns": [
{ "data": "Id", "autoWidth": true },
{ "data": "TransCode", "autoWidth": true },
{ "data": "TransDesc", "autoWidth": true }
]
});
});
$('#btnSearch').on("click", function () {
table.ajax.reload();
});