JQGRID 首次加上查询条件,再次加载的js
<script>
function editUser() {
console.log($("#editForm").serialize()); //表单序列化
$.post("${cpt}/user/updateUser",$("#editForm").serialize(),function (res) {
console.log(res); //返回更新结果
if(res.status){
alert(res.msg);
$("#updateUserModal").modal('hide');//关闭更新的模态框
findUser();//再次加载表格数据
}else{
alert(res.msg);
}
},"JSON")
}
</script>
完整增删改查jsp页面代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% application.setAttribute("cpt",request.getContextPath()); %>
<script>
$(function () {
var url ="${cpt}/user/getAllUser";
loadList(url);
})
function loadList(url) {
$("#userList").jqGrid({
styleUI:"Bootstrap",//用来指定jqgrid的主题样式 固定写死
url:url, //用来远程获取数据的址。返回json格式
datatype:"json", //用来指定服务器返回的数据类型; 默认是XML
mtype:"get", //用来指定请求方式
colNames:["编号","登陆名","密码","姓名","手机号","邮箱","状态","创建日期","最后编辑日期","编辑"], //用来指定表格中的标题列的名称
colModel:[ //colNames、colModel 需要成对出现
{name: "id"}, //居中
{name: "loginname"}, //单元格可编辑
{name: "pwd"}, //单元格可编辑
{name: "name"}, //单元格可编辑
{name: "phone"}, //单元格可编辑
{name: "email"}, //单元格可编辑
{name: "starts",
formatter:function (cellvalue) {
if(cellvalue ==0){
return '正常';
}
return '停用';
}}, //单元格可编辑
{name: "createdate",width:"260"}, //单元格可编辑
{name: "editdate",width:"260"}, //单元格可编辑
// {name: "age",
// formatter:function(cellvalue, options, rowObject){ //用来对数据进行二次处理
// //cellvalue 这一列的值 //options 当前对象的属性
// //rowObject 当前行的所有值
// console.log(cellvalue);
// console.log(options);
// console.log( rowObject);
// // var age = rowObject.age;
// // if(age>30){
// // return "真大";
// // }else{
// // return "还小";
// // }
// if(cellvalue>30){
// return "<font color='red'>"+cellvalue+"</font>"
// }
// return "<font color='green'>"+cellvalue +"</font>"
// }},
// {name: "bir"},
// {name:"dept.name"},
{name:"id",
formatter:function (cellvalue, options, rowObject) {
var temps='<button onclick="return selectUserById('+cellvalue+')" class="btn btn-danger btn-sm">修改</button> ' +
'<button onclick="return deleteUser('+cellvalue+')" class="btn btn-warning btn-sm">删除</button>'
return temps;
}},
],
pager:"#gridPage",//用来定义分页工具栏 后台可以定义 page(当前面) row(每页显示多少页)
viewrecords:true, //展示总条数
rowNum:20, //每页显示多少条。默认20
rowList:[10,20,30,40,50], //用来定义一个下拉列表,可选页面展示多少条
caption:"人员信息表",
hidegrid:false, //不显示收缩按钮
autowidth: true, //自适应父容器
height:"600px",//默认高度
})
}
function deleteUser(id){
if(confirm("是否删除该数据!")){
$.post("${cpt}/user/deleteUserById","id="+id,function (res) {
if(res.status){
alert(res.msg);
findUser();//删除成功,需要刷新
}else{
alert(res.msg);
}
},"JSON")
}
}
function selectUserById(id){
$.post("${cpt}/user/selectUserById","id="+id,function (res) {
console.log(res);
$("#editStaticId").text(res.id);
$("#editId").val(res.id);
$("#editName").val(res.name);
$("#editPwd").val(res.pwd);
$("#editPhone").val(res.phon