bootstrap -table單元格,删除,修改事件
// 表格資料處理
function tableData(data) {
$(selectors.table).bootstrapTable('destroy');
$(selectors.table).bootstrapTable({
data: data,
striped: false,
pagination: true,
cache: false, //是否使用緩存,預設為true,是以一般情況下需要設定一下這個屬性(*)
sidePagination: "client", //分頁方式:client用戶端分頁,server服務端分頁(*)
pageNumber: 1, //初始化加載第一頁,預設第一頁
pageSize: 5,
pageList: [5, 10, 20, 30, 50, 100],
toolbar: "#toolbar",
search: false,
showRefresh: false,
formatLoadingMessage: function() { // 表格生成過程中執行的方法
return '請稍等,正在加載中...'; // 傳回一串等待文字
},
columns: [
{
field: "id",
title: "#",
align: "center"
},
{
field: "name",
title: "使用者名",
align: "center"
},
{
field: "departId",
title: "部門ID",
align: "center",
visible: false //不可見
},
{
field: "do",
title: "操作",
align: "center",
//根據此使用者是存在還是已被删除,來确定是[删除 編輯]還是[恢複]
formatter: function(val, row, index) {
//删除,标記,參數配置
var doStr = '';
doStr = '<a class="btn-delete">删除</a><a class="btn-edit">修改</a>';
return doStr;
},
events: {
"click .btn-delete": function(event, val, row, index) {
console.log(row.id);
swal({
title: "溫馨提示",
text: "确定要删除" + row.name + "員工嗎?",
type: "warning",
showCancelButton: true,
confirmButtonText: "删除",
cancelButtonText: "取消",
confirmButtonColor: "#f05050",
closeOnConfirm: true,
allowEscapeKey: false,
}, function(isConfirm) {
if (isConfirm) {
var successFn = function(res) {
console.log(res);
error.listen(res.code).not(function() {
swal({
title: "删除員工成功!",
type: "success",
});
});
}
var failed = function(res) {
console.log(res);
swal({
title: "删除員工失敗!",
type: "error",
});
}
oDataSourse.deleteUser(row.id).then(successFn, failed);
}
})
},
"click .btn-edit": function(event, val, row, index) {
$(selectors.updateStaffModal).modal("show");
console.log(row);
}
}
},
]
});