<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>界面</title>
<link rel="stylesheet" type="text/css" href="./easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="./easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="./easyui/demo/demo.css">
<script type="text/javascript" src="./easyui/jquery.min.js"></script>
<script type="text/javascript" src="./easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
var base = '<%=request.getAttribute("base")%>';
$(function(){
//ip与用户配置表
$('#ds').datagrid({
url:base +"/student/query",
pagination:false,//显示底部分页栏
singleSelect:true,
method: 'GET',
columns:[[
{field:'id',title:'Id',width:50,align:'center',editor:'text'},
{field:'studentName',title:'用户名',width:100,align:'center',editor:'text'},
{field:'password',title:'密码',width:100,align:'center',editor:'text'},
{field:'address',title:'地址',width:200,align:'center',editor:'text'},
{field:'_opt',title:'操作',width:100,align:'center',formatter:function(value,rec){
var btn = '<input type="button" onclick="update()" value="保存"/>';
return btn;
}}
]],
toolbar : [ {
text : '添加',
iconCls : 'icon-add',
handler : function(){
$('#ds').datagrid("appendRow",{id:'',studentName:'',password:'',address:''});
}
}, '-', {
text : '删除',
iconCls : 'icon-remove',
handler : function(){
var _sR = $('#ds').datagrid("getSelected");
var q = confirm("确认删除吗?");
if(q){
$('#ds').datagrid('acceptChanges');
var _sr = $('#ds').datagrid("getSelected");
var _delURL = base +"/student/delete";
var _data = JSON.stringify(_sr);
$.ajax({
type: 'POST',
url: _delURL,
data:_data,
dataType:"json",
contentType:"application/json",
success: function(msg){
alert("删除成功");
$('#ds').datagrid("reload");
}
});
}else{
$('#ds').datagrid('acceptChanges');
}
}
} ],
onClickCell : function(index,field){
$('#ds').datagrid('acceptChanges');
$('#ds').datagrid('beginEdit', index);
},
onLoadSuccess:function(data){
rows = $('#ds').datagrid("getRows").length;
}
});
});
function update(){
$('#ds').datagrid('acceptChanges');
var _selectedRow = $('#ds').datagrid("getSelected");
var _updURL = base +"/student/update";
var _addURL = base +"/student/add";
var _data = JSON.stringify(_selectedRow);
var newrows = $('#ds').datagrid("getRows").length;
if(newrows== rows){
$.ajax({
type:'POST',
url: _updURL,
data: _data,
dataType:"json",
contentType:"application/json",
success: function(msg){
$('#ds').datagrid("reload");
alert("修改成功");
}
});
}else{
$.ajax({
type: 'POST',
url: _addURL,
data: _data,
dataType:"json",
contentType:"application/json",
success: function(msg){
$('#ds').datagrid("reload");
alert("添加成功");
}
});
}
};
</script>
</head>
<body>
<table id="ds" title="" style="width:602px"></table>
</body>
</html>