您的位置:首页 > 产品设计 > UI/UE

EasyUI datagrid列排序

2016-02-26 11:48 399 查看
          选课系统中对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();
}
}

      效果图

                      


    项目实践中发现问题解决问题,在问题中成长。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: