// 1、定义一个表格容器
<div id="ccT">
<table id="ArbetTable"> </table>
</div>
<script>
// 3、初始化表格
$(function() {
var oTable = new TableInit();
oTable.Init();
});
// 2、定义表格格式
var TableInit = function() {
var oTableInit = new Object();
oTableInit.Init = function() {
$('#ArbetTable').bootstrapTable({
url : 'showTable',
method : 'post',
//toolbar: '#toolbar',
striped : true,
cache : false,
pagination : true,
sortable : false,
queryParams : oTableInit.queryParams,
showToggle : true,
sidePagination : "server",
pageList : [ 4, 10 ],
pageNumber : 1,
pageSize : 4,
showColunms : true,
clickToSelect : true,
showRefresh : true,
search : false,
uniqueId : "id",
contentType : "application/x-www-form-urlencoded",
columns : [ {
field : 'id',
title : '学号'
}, {
field : 'name',
title : '姓名'
}, {
field : 'sex',
title : '性别'
}, {
field : 'age',
title : '年龄'
}, {
field : 'operate',
title : '操作',
events : operateEvents,
formatter : operateFormatter
} ]
});
};
oTableInit.queryParams = function(params) {
var temp = {
limit : params.limit,
offset : params.offset
};
return temp;
};
return oTableInit;
};
function operateFormatter(value, row, index) {
return [ '<button class="btn btn-warning" id="edit">编辑</button>',
'<button class="btn btn-danger" id="delete">删除</button>' ]
.join(" ");
}
window.operateEvents = {
"click #delete" : function(e, value, row, index) {
layer.msg("确认删除?", {
time : 0,
icon : 7,
btn : [ "是", "否" ],
yes : function(index) {
layer.close(index);
$.ajax({
type : "POST",
url : "deleteStudent",
data : "id=" + row["id"],
contentType : "application/x-www-form-urlencoded",
async : false,
success : function(result) {
location.reload();
},
error : function(result) {
layer.alert('删除失败', {
icon : 5
});
}
});
}
});
},
"click #edit" : function(e, value, row, index) {
layer.open({
type : 1,
area : [ '600px', '360px' ],
shadeClose : true, //点击遮罩关闭
title : '修改学生记录',
content : $('#bidderDiv')
});
$("#id").val(row["id"]);
$("#name").val(row["name"]);
$("#sex").val(row["sex"]);
$("#age").val(row["age"]);
$("#dilivery").off("click").on("click", function() {
var record = {
oldid : row["id"],
id : $('#id').val(),
name : $('#name').val(),
sex : $('#sex').val(),
age : $('#age').val()
}
//Ajax调用处理
$.ajax({
type : "POST",
url : "updateStudent",
datatype : "text",
contentType : "application/json",
data : JSON.stringify(record),
async : true,
success : function(result) {
layer.alert('修改成功', {
icon : 6
});
},
error : function(result) {
layer.alert('修改失败', {
icon : 5
});
}
})
});
}
}
</script>
网友评论