JQuery DataTable刪除行后的頁面更新利用Ajax解決
更新時間:2013年05月17日 17:07:07 作者:
使用Jquery的DataTable進行數(shù)據(jù)表處理非常方便,常遇到的一個問題就是刪除一行后頁面必須進行更新,下面與大家分享下使用Ajax的解決方法
使用Jquery的DataTable進行數(shù)據(jù)表處理非常方便,常遇到的一個問題就是刪除一行后頁面必須進行更新,需要注意的方法如下:前臺頁面中初始化table時注意:
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, 這個必須設(shè)置,這樣就可以在刪除返回時,保留在同一頁上'bStateSave': true, 這個必須設(shè)置,這樣就可以在刪除返回時,保留在同一頁上
刪除的代碼如下:
function deleteConfirm(deleteID)
{
$.modal.confirm('確實要刪除此用戶嗎?', function()
{
$.ajax('servlet/DeleteUser', {
dataType : 'json',
data: {
userID: deleteID
},
success: function(data)
{
if (data.success =='true')
{
$.modal.alert('刪除成功!');
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('刪除發(fā)生錯誤,請聯(lián)系管理員!');
}
},
error: function()
{
$.modal.alert('服務(wù)器無響應(yīng),請聯(lián)系管理員!');
}
});
}, function()
{
//$.modal.alert('Meh.');
});
};
其中只要是需要判斷一下當前頁中是否有數(shù)據(jù),如果是最后一條的話,就在刪除后調(diào)用
$("#sorting-advanced").dataTable().fnPageChange( 'previous', true );已回到上一頁中
注意$("#sorting-advanced").dataTable().fnPageChange( 'previous'); 是不行的,必需進行刷新,否則頁面中顯示的iDisplayStart會從cookie中取得,還是刪除前的iDisplayStart
復(fù)制代碼 代碼如下:
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, 這個必須設(shè)置,這樣就可以在刪除返回時,保留在同一頁上'bStateSave': true, 這個必須設(shè)置,這樣就可以在刪除返回時,保留在同一頁上
刪除的代碼如下:
復(fù)制代碼 代碼如下:
function deleteConfirm(deleteID)
{
$.modal.confirm('確實要刪除此用戶嗎?', function()
{
$.ajax('servlet/DeleteUser', {
dataType : 'json',
data: {
userID: deleteID
},
success: function(data)
{
if (data.success =='true')
{
$.modal.alert('刪除成功!');
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('刪除發(fā)生錯誤,請聯(lián)系管理員!');
}
},
error: function()
{
$.modal.alert('服務(wù)器無響應(yīng),請聯(lián)系管理員!');
}
});
}, function()
{
//$.modal.alert('Meh.');
});
};
其中只要是需要判斷一下當前頁中是否有數(shù)據(jù),如果是最后一條的話,就在刪除后調(diào)用
$("#sorting-advanced").dataTable().fnPageChange( 'previous', true );已回到上一頁中
注意$("#sorting-advanced").dataTable().fnPageChange( 'previous'); 是不行的,必需進行刷新,否則頁面中顯示的iDisplayStart會從cookie中取得,還是刪除前的iDisplayStart
您可能感興趣的文章:
- jquery ajax實現(xiàn)批量刪除具體思路及代碼
- PHP jQuery+Ajax結(jié)合寫批量刪除功能
- PHP ajax+jQuery 實現(xiàn)批量刪除功能實例代碼小結(jié)
- JQuery+ajax實現(xiàn)批量上傳圖片(自寫)
- jQuery通過ajax快速批量提交表單數(shù)據(jù)
- jQuery之a(chǎn)jax刪除詳解
- jQuery ajax中使用confirm,確認是否刪除的簡單實例
- 如何從jQuery的ajax請求中刪除X-Requested-With
- jQuery+css3實現(xiàn)Ajax點擊后動態(tài)刪除功能的方法
- 基于php(Thinkphp)+jquery 實現(xiàn)ajax多選反選不選刪除數(shù)據(jù)功能
- jQuery+ajax實現(xiàn)批量刪除功能完整示例
相關(guān)文章
easyui 中的datagrid跨頁勾選問題的實現(xiàn)方法
很多朋友都遇到這樣的需求,easyui的datagrid分頁顯示數(shù)據(jù),如果有需求要求勾選多條數(shù)據(jù)且不再同一頁中,easyui會保存在其他頁選中的數(shù)據(jù)嗎?小編結(jié)合資料自己整理了一篇文章,需要的的朋友參考下吧2017-01-01jquery.cvtooltip.js 基于jquery的氣泡提示插件
顯示氣泡提示的前提是,一定會有一個被提示的對象,默認的位置是根據(jù)body來計算的,這樣的壞處就是如果頁面內(nèi)容發(fā)生了變化,而氣泡的位置沒有改變,導(dǎo)致提示目的失敗。2010-11-11jQuery 實現(xiàn)鼠標畫框并對框內(nèi)數(shù)據(jù)選中的實例代碼
本文通過實例代碼給大家介紹了jQuery 實現(xiàn)鼠標畫框并對框內(nèi)數(shù)據(jù)選中的實例代碼,非常不錯,具有參考借鑒價值,需要的朋友參考下吧2017-08-08jquery+json實現(xiàn)動態(tài)商品內(nèi)容展示的方法
這篇文章主要介紹了jquery+json實現(xiàn)動態(tài)商品內(nèi)容展示的方法,涉及jQuery操作及解析json格式數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2016-01-01