i have three select fields on last select onchange event call.(function clas). First time it runs and datatables initilize but when the second time event runs and function call and datatable again initilize it makes Error. i dont know how to set the format or how i can initialize datatable outside the function . i just want to initilize datatables for once but call ajax every time with respect to function here is my code And also ajax runs first time automatically with datatable initilization but second time ajax call when event run and function call
function clas(src)
{
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"requests/add_students/fetch.php",
type:"POST",
data: {
"class_name": 2,
"class_section": 3,
"class_session": 4
}
},
dom: 'lBfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [ 0, ':visible' ]
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [ 1, 2 ]
},
},
{
extend: 'csvHtml5',
exportOptions: {
columns: [ 1, 2 ]
},
}
],
"lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
"columnDefs":[
{
"targets":[0, 3, 4],
"orderable":false,
},
],
});
}