It is very convenient to use Jquery's DataTable for data table processing. A common problem is that the page must be updated after deleting a row. The methods that need to be paid attention to are as follows: When initializing the table in the front page, pay attention to:
var table = $('#sorting-advanced');
table.dataTable({
'bServerSide': true,
'sAjaxSource': 'servlet/UserList<%=queryString%>',
'bProcessing': true, 'bStateSave': true,
'aoColumnDefs': [
{ 'bSortable': false, 'aTargets': [0,1,6]}
],
'sPaginationType': 'full_numbers',
'sDom': '<" dataTables_header"lfr>t<"dataTables_footer"ip>',
'fnInitComplete': function( oSettings )
{
// Style length select
table.closest('.dataTables_wrapper').find ('.dataTables_length select').addClass('select blue-gradient glossy').styleSelect();
tableStyled = true;
}
});
' bStateSave': true, this must be set, so that it can remain on the same page when deleting and returning. 'bStateSave': true, this must be set, so that it can remain on the same page when deleting and returning.
The deleted code is as follows:
function deleteConfirm( deleteID)
{
$.modal.confirm('Are you sure you want to delete this user?', function()
{
$.ajax('servlet/DeleteUser', {
dataType : 'json',
data: {
userID: deleteID
},
success: function(data)
{
if (data.success =='true')
{
$.modal.alert('Delete successfully!');
start = $("#sorting-advanced").dataTable().fnSettings()._iDisplayStart;
total = $ ("#sorting-advanced").dataTable().fnSettings().fnRecordsDisplay();
window.location.reload();
if((total-start)==1){
if (start > 0) {
$("#sorting-advanced").dataTable().fnPageChange( 'previous', true );
}
}
}
else
{
$.modal.alert('Deletion error occurred, please contact the administrator!');
}
},
error: function()
{
$.modal.alert('The server is not responding, please contact the administrator!');
}
});
}, function()
{
//$ .modal.alert('Meh.');
});
};
As long as you need to judge whether there is data in the current page, if it is the last one, Just call
$("#sorting-advanced").dataTable().fnPageChange( 'previous', true ); just after deletion; you have returned to the previous page
Note $("#sorting-advanced" ).dataTable().fnPageChange( 'previous'); is not possible. It must be refreshed. Otherwise, the iDisplayStart displayed on the page will be obtained from the cookie or the iDisplayStart before deletion.