EasyUI datagrid列排序

          选课系统中对easyUI datagrid排序的功能进行了实践。发现easyui的人性化处理真滴不错。给开发人员带来很大的便利。完整版代码分析给有需要的人。       

html代码
<table id="dg" title="已配置轮次" class="easyui-datagrid"
		url="${pageContext.request.contextPath}/queryRoundinfo"
		data-options="fitColumns:true,rownumbers: true, pagination:true" style="height:550px" >
		<thead>
			<tr>
				<th data-options="field:'roundNo',width:30,sortable : true,sortname:'roundNo',sortvalue:'ASC',align:'center'">轮次名称</th>
				<th  data-options="field:'beginTime',sortable : true,width:30,align:'center'" >开始时间</th>
				<th data-options="field:'endTime', sortable : true,width:30,align:'center'">结束时间</th>				
			</tr>
		</thead>

	</table>

      首先设置每列是否可排序属性sortable:true,并默认选择列作为排序列并设置升序或降序 如上述代码第一列。接下来在controller中获取sort和order,并传递给后台数据操作层,通过sql实现数据查询排序。

java  后台controller将接收参数

    

Controller
	@RequestMapping("/queryRoundinfo")
	public void queryRoundinfo(HttpServletRequest request,
			HttpServletResponse response, String page, String rows,String sort,String order)	throws Exception {
	String dataBaseName = "itoo_basic";
			// map转换后的返回值
		List mapList = new ArrayList();
		// 获取查询条件
		String SortName = request.getParameter("sort");
		//首次加载表格时sort和order为null
		if(SortName == null){
			SortName ="beginTime";
		}
		String SortValue =request.getParameter("order");
		if(SortValue == null){
			SortValue = "asc";		
		}
		// 获取查询条件
		String condition = request.getParameter("condition");
		// 将分页信息转换为整型
		int pageNum = Integer.parseInt(page);
		int pageSize = Integer.parseInt(rows);
		try {
			// 有条件查询
			if (condition != null && condition.length() != 0) {
				/* 模糊查询课程名称 */

				mapList = chooseCourseStatisticsBean.queryfuzzyRoundinfo(
						pageNum, pageSize, dataBaseName, condition, SortName,
						SortValue);
			} else {
				mapList = chooseCourseStatisticsBean.queryRoundinfo(pageNum,
						pageSize, dataBaseName, SortName, SortValue);

			}
			jacksonJsonUntil.beanToJson(response, mapList);

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

      效果图

                      

    项目实践中发现问题解决问题,在问题中成长。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值