easyui datagrid点击表头排序

datagrid可以实现点击表头进行排序,按方式可分两种:仅前台排序和后台排序。要实现列的排序,必须要设置需要参与排序的列的sortable=”true”属性。

一.仅前台排序是只针对当前页的数据进行排序

要实现这种排序,必须设置datagrid的remoteSort=”false”,因为该属性默认值为true。如果要设置页面打开时默认某列排序,需要设置sortname=”列属性值”

例如:

<table id=”dg” singleSelect=”true” style=”width:100%,height:100%” rownumbers=”true” border=”true” pagination=”true” pageSize=”100″
fit=”true” toolbar=”#tool” pageList=”[10,30,50,100]” url=”<c:url value=’/nnmis/view/zzjg/searchYrxx.tg’/>” sortname=”orgname” remoteSort=”false”>
<thead>
<tr>
<th field=”id” width=”80″ hidden=”true”></th>
<th field=”orgname” width=”130″ sortable=”true”>部门</th>
<th field=”loan” width=”50″ sortable=”true”>借调</th>
<th field=”personname” width=”130″ sortable=”true”>人员名</th>
<th field=”position” width=”130″ sortable=”true”>职务</th>
<th field=”mb” width=”130″ sortable=”true” hidden=”true”>手机</th>
<th field=”age” width=”110″ sortable=”true” hidden=”true”>年龄</th>
<th field=”graduate” width=”130″ sortable=”true” hidden=”true”>毕业院校</th>
<th field=”degree” width=”130″ sortable=”true” hidden=”true”>学历</th>
<th field=”zhicheng” width=”130″ sortable=”true” hidden=”true”>职称</th>
<th field=”experience” width=”130″ sortable=”true” >工作职责</th>
<th field=”tel” width=”130″ sortable=”true” >固话</th>
<th field=”photo” width=”110″ sortable=”true”>个人照片</th>
</tr>
</thead>
</table>

二.数据库层的排序

该排序方式指定remoteSort=”true”,然后在后台使用String sort = request.getParameter(“sort”);获取要排序的列名,String order = request.getParameter(“order”);获取排序方式。把这两个参数传递给服务层去处理数据再返回前台即可。

当用户点击列头时,会被datagrid的onSortColumn方法捕获,该方法包括了sort和order两个参数。

This entry was posted in Computer, Java, javascript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s