Remove row on serverSide preserving table pagination state
Remove row on serverSide preserving table pagination state

Hi, im having an issue with the pagination when i remove a row. So im using the serverSide option to get the data from the backend. When i remove a row, i want to stay in the same position where i was, that is to say preserving the pagination, but only when needed, i mean, if im on the page 2 and there is only one row, when deleting the mentioned row i need it to go back to the previous page where there is the rest of the rows. But what happen is that it stay in the same page (page 2) showing 0 records as you can see in the attached image. I know that that happens because im passing false to the draw method so it prevent it from changing the page. But is there a way to move to the previous page only when needed?. By the way im using a laravel + vue + inertia setup.
Code:
const deleteOwner = (id) => {
Swal.fire({
title: '¿Seguro?',
text: 'Esta acción eliminará permanentemente el registro.',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '¡Sí, bórralo!',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
router.visit(route('owners.delete', id), {
method: 'delete',
preserveScroll: true,
preserveState: true,
onSuccess: () => {
const row = dataTable.value.dt.row(`#${id}`)
row.remove().draw(false);
Swal.fire({
title: "¡Éxito!",
text: "Propietario borrado correctamente.",
icon: "success",
showCloseButton: true,
showConfirmButton: false,
});
}
});
}
});
};
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Replies
I think you might have hit a limitation in the DataTables server-side processing code here I'm afraid. You might need to use
page.info()
to determine if the page should be held or shifted to a different one.I'll need to look into this more, thanks for bringing it up.
Allan
Thank you for responding. If you have any update pls let me know!