1、在list.js文件中写入代码:
//实现排序
//0:升序
$(".fa-caret-up").on("click",function(){
debugger;
var orderProperty=$(this).siblings("input").val();
$(".orderProperty").val(orderProperty);
$(".orderDirection").val("ASC");
$listForm.submit();
});
//1:降序
$(".fa-caret-down").on("click",function(){
debugger;
var orderProperty=$(this).siblings("input").val();
$(".orderProperty").val(orderProperty);
$(".orderDirection").val("DESC");
$listForm.submit();
});
定义二个隐藏域在页面中:
<!-- 排序 隐藏域 -->
<input type="hidden" name="orderDirection" class="orderDirection" value="${(paramter.orderDirection)!''}"/>
<input type="hidden" name="orderProperty" class="orderProperty" value="${(paramter.orderProperty)!''}"/>
在需要排序的字段中写入样式,但是需要注意的是value值与数据库中的字段是对应的
<th>领取总数<i class="fa fa-fw fa-caret-up fa-lg"></i>
<i class="fa fa-fw fa-caret-down fa-lg"></i>
<input type="hidden" value="receive_amount"/>
</th>