$(function () {javascript
var tabel = $('#userlist').DataTable({
destroy: true, //Cannot reinitialise DataTable,解決從新加載表格內容問題
bProcessing: true, //DataTables載入數據時,是否顯示‘進度’提示
bStateSave: false, //是否打開客戶端狀態記錄功能,此功能在ajax刷新紀錄的時候不會將個性化設定回覆爲初始化狀態
aLengthMenu: [10, 20, 40, 60, 100, 1000], //更改顯示記錄數選項
iDisplayLength: 10, //默認顯示的記錄數
bInfo: true, //是否顯示頁腳信息,DataTables插件左下角顯示記錄數
bPaginate: true, //是否顯示(應用)分頁器
autoWidth: true, //是否自適應寬度
bScrollCollapse: true, //是否開啓DataTables的高度自適應,當數據條數不夠分頁數據條數的時候,插件高度是否隨數據條數而改變
sPaginationType: "full_numbers", //詳細分頁組,能夠支持直接跳轉到某頁
bSort: false, //是否啓動各個字段的排序功能
bFilter: true, //是否啓動過濾、搜索功能
bServerSide: true, //開啓此模式後,你對datatables的每一個操做 每頁顯示多少條記錄、下一頁、上一頁、排序(表頭)、搜索,這些都會傳給服務器相應的值。
"ajax": {
url: "/Ajax/UserMgrAjax.ashx?cmd=userList",
type: "POST"
},
columns: [
{
"sWidth": "4%",
"sClass": "text-center",
"data": null,
"targets": 0
},
{
"sWidth": "4%",
"sClass": "text-center",
"data": "u_id",
"render": function (data, type, full, meta) {//這裏就是要顯示的checkbox多選框了
return '<input type="checkbox" class="checkchild" value="' + data + '" />';
},
"bSortable": false
},
{ "sClass": "text-center", "data": "u_name" },
{ "sClass": "text-center", "data": "u_tel" },
{
"sClass": "text-center",
"data": "u_sex",
"render": function (data, type, row, meta) {
var content = "保密";
if (data == "1")
content = "男";
if (data == "2")
content = "女";
return content;
}
},
{ "sClass": "text-center", "data": "u_age" },
{ "sClass": "text-center", "data": "u_registerdate" },
{
"sClass": "text-center",
"data": "u_state",
"render": function (data, type, row, meta) {
var content = "非正常";
if (data == "0")
content = "正常";
if (data == "1")
content = "鎖定";
return content;
}
},
{
"sClass": "text-center",
"data": "u_registerdate",
render: function (data, type, row, meta) {
return "<a id='edit' title='編輯' class='glyphicon glyphicon-edit nounderline' href='javascript:Edit("+row.u_id+");'></a>";
}
}
],
//這個應該是重繪的回調函數
fnDrawCallback: function () {
var startIndex = this.api().context[0]._iDisplayStart;//獲取到本頁開始的條數
this.api().column(0).nodes().each(function (cell, i) {
//翻頁序號連續
cell.innerHTML = startIndex + i + 1;
});
},
});java
//------------------------------------------------------------------------------------------------------------------------------------------node
//刪除
$("#del").click(function () {
var ids = "";
$('.checkchild').each(function () {
if ($(this).is(':checked')) {
ids += $(this).val()+",";
}
});
if (ids != "") {
$.ajax({
type: "Post",
url: "UserList.aspx/DelUser",
//方法傳參的寫法必定要對,str爲形參的名字
data: "{'ids':'" + ids + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//返回的數據用data.d獲取內容
UserList();
layer.msg(data.d);
}
});
} else {
layer.msg("請選擇行",{offset: ['300px', '700px']});
return;
}
});ajax
});json