Fix Add Kart
Set auto refresh Datatable on delete and add
This commit is contained in:
@ -165,8 +165,10 @@ function listKarts() {
|
||||
url: api_url + 'karts/',
|
||||
dataType: 'json',
|
||||
success: function (data, status) {
|
||||
console.log(data);
|
||||
$('#dataTable_kart_list').DataTable({
|
||||
if(tableListKart instanceof $.fn.dataTable.Api){
|
||||
tableListKart.destroy();
|
||||
}
|
||||
tableListKart = $('#dataTable_kart_list').DataTable({
|
||||
data: data,
|
||||
columns: [
|
||||
{
|
||||
@ -176,7 +178,7 @@ function listKarts() {
|
||||
'<i class="fas fa-edit"></i>' +
|
||||
'</a>' +
|
||||
' ' +
|
||||
'<a href="#" onclick="if ( confirm( \'Do you want to delete the kart\' ) ) {deleteKarts('+data+')}" class="btn btn-danger btn-circle">' +
|
||||
'<a href="#" onclick="if ( confirm( \'Do you want to delete the kart\' ) ) {deleteKarts('+data+','+meta.row+')}" class="btn btn-danger btn-circle">' +
|
||||
'<i class="fas fa-trash"></i>' +
|
||||
'</a>';
|
||||
}
|
||||
@ -197,16 +199,15 @@ function listKarts() {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteKarts(id) {
|
||||
function deleteKarts(id, index) {
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
crossDomain: true,
|
||||
url: api_url + 'karts/'+id+'/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: function (data, status) {
|
||||
$.notify("Delete done!", "success");
|
||||
showKarts();
|
||||
tableListKart.row(index).remove().draw();
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
@ -224,11 +225,14 @@ function addKarts(data) {
|
||||
data: data,
|
||||
success: function (data, status) {
|
||||
$.notify("Update done!", "success");
|
||||
//showKarts();
|
||||
$('#modal_newkart').modal('hide');
|
||||
$("#saveKartChanges").prop('disabled', false);
|
||||
listKarts()
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
|
||||
$("#saveKartChanges").prop('disabled', false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -1 +1,2 @@
|
||||
var api_url = 'http://timelaps.local:8000/api/v1/';
|
||||
var api_url = 'http://timelaps.local:8000/api/v1/';
|
||||
var tableListKart = '';
|
Reference in New Issue
Block a user