easyUI 表格
1.创建
<table id ="ID"></table>
2.属性
dategrid:
columns
列的定义的数组
URl:访问远程数据的数组
[“total“:总记录条数,“row”:[{行的对象}]]
toolbar:工具栏
pagination=true/false
是否显示分页栏
列
field
列对应的属性名
title
表头标题
checkbox:true/false
是否是复选框列
必须要同时设置filed
1.创建表格
<table id="hh"></table>
2、创建datagrid显示学生信息,并创建相应的按钮
<script type="text/javascript">
$(function(){ $("#hh").datagrid({ url:'StudentServlet',
//冻结列
frozenColumns:[[
{field:'id',checkbox:true},//复选框
{field:'sno',title:'学号',width:100} ]],
//定义列
columns:[[ {field:'sname',title:'姓名',width:200,align:'center'},
{field:'ssex',title:'性别',width:200,align:'center',
formatter: function(value,row,index){
if(value == '男'||value == 'f')
{
return '男';
}
else
{
return '女';
}
},
styler:function(value,row,index){
if(value=='男'|| value=='f')
{
return 'background-color:#ccccff;color:red;'; }
}
}, {field:'sbirthday',title:'生日',width:200,align:'right'},
{field:'sclass',title:'班级',width:200,align:'center'} ]] ,
fitColumns:true, //列自适应宽度,不能和冻结列同时设置为true
striped:true, //斑马线
idField:'sno', //主键列
rownumbers:true, //显示行号
singleSelect:false, //是否单选
pagination:true, //分页栏
pageList:[8,16,24,32] , //每页行数选择列表
pageSize:8 , //初始每页行数
remoteSort:false, //是否服务器端排序,设成false才能客户端排序
//sortName:'unitcost', //定义哪些列可以进行排序。 toolbar:[ {
iconCls:'icon-search',
text:'查询',
handler:function(){
$("#hh").datagrid('load')},//加载和显示第一页的所有行 }, {
iconCls:'icon-add',
text:'添加',
handler:function(){
//清除表单旧数据
$("#form1").form("reset");//重置表单数据 $("#saveStu").dialog('open');
},
},
{
iconCls:'icon-edit',
text:'修改',
handler:function(){
},
},
{
iconCls:'icon-delete',
text:'删除',
handler:function(){
},
}
],
});
}) </script>
3.创建点击添加按钮时的弹窗dialog,并通过post方式发送表单的信息传给URL地址的Servlet层



<div class="easyui-dialog" id="saveStu" style="width:400px; height:300px"
title="添加学生"
data-options="{
closed:true,
modal:true,
buttons:[{
text:'保存',
iconCls:'icon-save',
handler:function(){
$('#form1').form('submit',{ url:'SaveStudentServlet',
onSubmit:function(){
var isValid = $(this).form('validate');
if(!isValid)
{
$.messager.show({ title:'消息',
msg:'数据验证未通过'
});
}
return isValid; // 返回false终止表单提交
},
success:function(data){
var msg = eval('('+ data +')');//eval是js的方法
if(!msg.success)
{
alert(msg.message);
}
else
{
$('#hh').datagrid('load');
$.messager.show({ title:'消息',
msg:'数据验证通过,保存成功'
});
$('#saveStu').dialog('close');
} }
});
} }, {
text:'取消',
iconCls:'icon-cancel',
handler:function(){$('#saveStu').dialog('close')},
}]
}">
<form action="" id="form1" method="post"><br><br>
<table border="0" width=100%>
<tr>
<td align="right" width="30%">学号:</td>
<td>
<input class="easyui-textbox" id="sno" name="sno"
data-options="required:true,validType:'length[3,3]'">
</td>
</tr>
<tr>
<td align="right" width="30%">姓名:</td>
<td>
<input class="easyui-textbox" id="sname" name="sname"
data-options="required:true,validType:'length[2,3]'">
</td>
</tr>
<tr>
<td align="right" width="30%">性别:</td>
<td>
<input type="radio" name="ssex" value="男" checked>男
<input type="radio" name="ssex" value="女">女 </td>
</tr> <tr>
<td align="right" >生日:</td>
<td>
<input class="easyui-datebox" id="sbirthday" name="sbirthday"
data-options="required:false,">
</td>
</tr> <tr>
<td align="right" >班级:</td>
<td>
<input class="easyui-textbox" id="sclass" name="sclass"
data-options="required:true,validType:'length[5,5]'">
</td>
</tr>
</table> </form> </div>
servlet层
package com.hanqi.web; import java.io.IOException;
import java.text.SimpleDateFormat; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.hanqi.entity.Student;
import com.hanqi.service.StudentService; /**
* Servlet implementation class SaveStudentServlet
*/
public class SaveStudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public SaveStudentServlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //转码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html"); //接受参数
String sno = request.getParameter("sno");
String sname = request.getParameter("sname");
String ssex= request.getParameter("ssex");
String sbirthday = request.getParameter("sbirthday");
String sclass = request.getParameter("sclass"); String msg = "{'success':true,'message':'保存成功'}";
if(sno != null)
{
try
{
Student stu = new Student();
stu.setSno(sno);
stu.setSclass(sclass);
stu.setSname(sname);
stu.setSsex(ssex);
if(sbirthday !=null && !sbirthday.trim().equals(""))
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
stu.setSbirthday(sdf.parse(sbirthday));
}
new StudentService().addStudent(stu);
}
catch(Exception e)
{
msg = "{'success':false,'message':'访问失败'}";
} response.getWriter().print(msg);
}
else
{ msg = "{'success':false,'message':'访问异常'}";
response.getWriter().print(msg);
} } /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }
service层
//添加保存
public void addStudent(Student stu)
{
new StudentDAO().insert(stu);
}
DAO层
//添加数据
public void insert(Student stu)
{
init(); se.save(stu); destroy(); }
easyUI 表格的更多相关文章
- datagrid-detailview.js easyui表格嵌套
datagrid-detailview.js easyui表格嵌套
- 关于easyui表格右侧多出来的那一列。
关于easyui表格右侧多出来的那一列,如下图,是给滚动条预留的位置,easyui表格默认就有的. 如果想要不显示:打开jQuery.easyui.min.js文件,找到wrap.width();所在 ...
- easyui表格自动换行
表格内容自动换行可以通过设计表格属性 nowrap:false来实现,默认值为true: 但是easyui并未提供,表头自动换行的解决方案,因为一般我们的数据表格列名都是固定的,想换行的话可以通过& ...
- EasyUI表格DataGrid格式化formatter用法
1.通过HTML标签创建数据表格时使用formatter <!DOCTYPE html> <html> <head> <meta charset=" ...
- EasyUI表格DataGrid前端分页和后端分页的总结
Demo简介 Demo使用Java.Servlet为后台代码(数据库已添加数据),前端使用EasyUI框架,后台直接返回JSON数据给页面 1.配置Web.xml文件 <?xml version ...
- easyui表格,单元格合并
easyui的合并单元格比较麻烦,官网提供一下方法 $('#tt').datagrid({ onLoadSuccess:function(){ var merges = [{ index:2, row ...
- EasyUI 表格点击右键添加或刷新 绑定右键菜单
例1 在HTML页面中设置一个隐藏的菜单(前提是已经使用封装的Easyui) 代码: <div id="contextMenu_jygl" class="easyu ...
- EasyUi 表格自适应宽度
第一次接触EasyUi想要实现表格宽度自适应,网上找了好多文章,都没有实现,有网友实现了可是自己看不懂.可能是太简单高手都懒得分享,现在把自己的理解和实现记录一下,希望可以帮到向自己一样的菜鸟,步骤如 ...
- easyui表格的增删改查
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
随机推荐
- 前端工具之Gulp
Gulp是一款前端自动化的工具,如果能熟练使用Gulp来进行开发一定可以节省很多的时间,也可以快速的提高工作效率. 在使用Gulp之前就是要配置好Gulp安装的环境,这是我们能使用Gulp快速开发的第 ...
- 练习:使用nmcli 配置网络连接
显示所有连接 # nmcli con show 显示活动连接的所有配置信息 # nmcli con show "System eth0" --->引号内为连接的网卡名称 显示 ...
- 【bzoj1725】[USACO2006 Nov]Corn Fields牧场的安排
题目描述 Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧场上的某几格土 ...
- PHP判断文件或者目录是否可写
在PHP中,可用is_writable()函数来判断一个 文件/目录 是否可写,详情如下: 参考 is_writable (PHP 4, PHP 5) is_writable — 判断给定的文件名是否 ...
- Swift3.0P1 语法指南——下标
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- redis使用简介
1.redis 支持"生产者与消费者模式"."订阅模式" 2.实时数据, 用数据类型.时间戳.数据内容,以二进制形式存取 3.查询时间.查询间隔时间.查询更新时 ...
- 分布式应用下的Redis单机锁设计与实现
背景 最近写了一个定时任务,期望是同一时间只有一台机器运行即可.因为是应用是在集群环境下跑的,所以需要自己实现类一个简陋的Redis单机锁. 原理 主要是使用了Redis的SET NX特性,成功设置的 ...
- time和datetime时间戳---python
time模块 time模块提供各种操作时间的函数 说明:一般有两种表示时间的方式: 1.时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的 2.以数 ...
- sqlserver中分区函数 partition by的用法
partition by关键字是分析性函数的一部分,它和聚合函数(如group by)不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录, partition by ...
- c/c++优化结构控制
一.表达式优化--使用替换程序中的乘除法 c/c++中的加减运算效率远远高于乘除运算,由于移位指令的执行速度和乘除法差不多,所以可以使用移位的方式来替换程序中的乘除法.一个数向右移一位,等于该数乘以2 ...