JQuery DataTable Delete Row page update use AJAX to solve _jquery

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.