当前位置:网站首页>easyui datagrid控件使用
easyui datagrid控件使用
2022-07-25 16:23:00 【迟早嘚秃】
datagrid控件使用
1.目标
把数据库的数据显示到tabs页面中,并且提供查询和分页
效果图:
**删除修改和新增后面在讲今天讲查询和把数据呈现到表格上面:
首先我们了解datagrid控件
是个数据表格控件:并且自带分页属性
jsp界面写个表格标签和需要工具栏
//表格
js界面
$(function() {})//自动运行
datagrid需要写在自运行里面**
$('#dg').datagrid({
//数据文件读取文件路径
url : $("#ctx").val() + '/book.action?methodName=books',
//分页工具栏属性
pagination : true,
//真正的自动展开/收缩列的大小,以适应网格的宽度,防止水平滚动。
fitColumns : true,
//定义工具栏我这里定义了搜索和新增按钮
toolbar : '#tb',
//列明
columns : [ [ {
//field是读取数据文件,属性要相同才能被读取
field : 'bid',
title : 'id',
width : 100
}, {
field : 'bname',
title : '名称',
width : 100
}, {
field : 'price',
title : '价格',
width : 100
}, {
field : '操作',
title : '操作',
width : 100,
align : "right",
formatter : function(value, row, index) {
return "<a href='javascript:void(0);' οnclick='xg()'>修改</a>" +
" <a href='javascript:void(0);' οnclick='del()'>删除</a> "
}
}
] ]
})
后面就是把后台数据传到js来了
得到数据方法
public List<Book> executeQuery(Book book, PageBean pageBean) throws Exception {
String bname = book.getBname();
String sql = "select * from t_mvc_book where 1=1";
//如果传了名字过来就加上模糊查询语句
if (StringUtils.isNotBlank(bname)) {
sql += " and bname like '%" + bname + "%'";
}
return super.executeQuery(sql, Book.class, pageBean);
}
将数据转化为datagrid需要的形式并且发送
public String books(HttpServletRequest req, HttpServletResponse resp) throws Exception {
//分页属性
PageBean pageBean = new PageBean();
//将分页传入
//在easyui中,点击下一页上一页等默认的分页效果,携带的参数是page/rows
//我封装的pageBean刚好是这两个属性
pageBean.setRequest(req);
//得到数据库的所有数据
List<Book> list = bookdao.executeQuery(book, pageBean);
//将数据变成需要的格式
Map<String, Object> map = new HashMap<String, Object>();
map.put("total", pageBean.getTotal());
map.put("rows", list);
//将数据转为josn并且发送回去
ResponseUtil.writem(resp, map);
return null;
}
搜索功能
给搜索设置点击事件
load将数据发送给后台
和前面dao包方法对应
$("#btn-search").click(function() {
$('#dg').datagrid('load', {
bname : $("#bname").val()
});
})
结果:

边栏推荐
- Waterfall flow layout
- PageHelper.startPage没有生效问题
- 记得那两句话
- [image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code
- The presentation logic of mail sending and receiving inbox outbox and reply to the problem of broken chain
- Gap Locks(间隙锁)
- How does win11's own drawing software display the ruler?
- Typescript learning 1 - data types
- 什么是链游系统开发?链游系统开发如何制作
- Cookie、cookie与session区别
猜你喜欢

IaaS基础架构云 —— 云网络

Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool
![Leetcode:528. select randomly according to the weight [ordinary random failure + prefix and dichotomy]](/img/fb/8178388f8c9ac80d95140378d24238.png)
Leetcode:528. select randomly according to the weight [ordinary random failure + prefix and dichotomy]
![Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]](/img/b5/5c7fc70b8025cf7ef21d645a3ac22e.png)
Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]

一文理解分布式开发中的服务治理

Differences between cookies, cookies and sessions

狂神redis笔记12

进程之间的通信(管道详解)

【ZeloEngine】反射系统填坑小结

Boomi荣获“多元化最佳首席执行官奖”和“职业成长最佳公司奖”,在大型公司类别中跻身50强
随机推荐
Typescript learning 2 - Interface
leetcode:154. 寻找旋转排序数组中的最小值 II【关于旋转排序数组的中后定位二分法】
Mysql读写锁
What is a physical firewall? What's the effect?
MySQL check whether the table is locked
[Shakespeare: keep the fun of being a man]
MySQL intent lock
Talk about how to use redis to realize distributed locks?
Exploration of 6-wire SPI transmission mode
I interviewed 8 companies and got 5 offers in a week. Share my experience
Crazy God redis notes 12
Record Locks(记录锁)
High score technical document sharing of ink Sky Wheel - Database Security (48 in total)
MySQL显式锁
C # simulation lottery
Permission management - role assignment menu
The second revolution of reporting tools
Lazy loading of pictures
可验证随机函数 VRF
Leetcode:154. find the minimum value II in the rotation sort array [about the middle and rear positioning dichotomy of the rotation sort array]