Using the jquery DataTable for data table processing is very convenient, often encountered a problem is to delete a row after the page must be updated, you need to pay attention to the following methods: When initializing table in the foreground page:
Copy Code code as follows:
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 when the deletion returns, it remains on the same page ' Bstatesave ': True, this must be set so that it remains on the same page when the delete is returned
the deleted code is as follows:
Copy Code code 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 successful! ');
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 (' delete error, please contact admin! ');
}
},
Error:function ()
{
$.modal.alert (' server not responding, please contact admin! ');
}
});
}, Function ()
{
$.modal.alert (' Meh. ');
});
};
As long as it is necessary to determine whether there is data in the current page, if the last one, it is called after the deletion
$ ("#sorting-advanced"). DataTable (). Fnpagechange (' previous ', true); Back to previous page
Note $ ("#sorting-advanced"). DataTable (). Fnpagechange (' previous '); is not possible, must be refreshed, otherwise the Idisplaystart displayed in the page will be obtained from the cookie, or before the deletion of the Idisplaystart