Level 2
after doing a thorough research and digging deep table.draw(); works on certain datatables..i used this code and it perfectly works propertycatstable.ajax.reload();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a datatable whereby upon adding or updating a specific record in it automatically updates the row without table refresh.
I have been able to achieve all that but when it comes to updating the datatable row it doesn't work. I am using table.draw(), but it doesn't fire up. I have initialized the datatable accordingly but when I run the draw() code it doesn't work.
Where might I be going wrong?
var propertycatstable = $('#propertycategorytable').DataTable({
processing: true,
serverside: true,
ajax: "{{ route('get_propertycategories') }}",
columns: [{
data: 'id'
}, {
data: 'propertycat_title'
}, {
data: 'status',
"render": function(data, type, row) {
if (row.status == '1') {
return 'Active';
} else {
return 'In_Active';
}
}
}, {
data: 'action',
name: 'action',
orderable: false,
searchable: false
}, ]
});
// add a new property category
$(document).ready(function() {
$('.modal-title').html('Create A New Property Category');
$('.save_button').html('Save Property Category');
var form = $('#propertcat_form')[0];
$('.save_button').click(function() {
$('.error_messages').html('');
var formdata = new FormData(form);
console.log(formdata);
$.ajax({
url: '{{ route("storepropertycat") }}',
method: 'POST',
processData: false,
contentType: false,
data: formdata,
success: function(response) {
alertify.set('notifier', 'position', 'top-right');
alertify.success(response.success);
propertycatstable.draw(); //this is the code that isn't firing
$('.propertycategory').modal('hide');
console.log(response)
}
}
Please or to participate in this conversation.