在使用layui中的搜索功能時需要用到表格重載,表格重載的格式如下:
table.reload(ID, options, deep)
其中參數 ID 要重載的表格的 id
參數 options 即為各項基礎參數
參數 deep:是否采用深度重載(即參數深度克隆,也就是重載時始終攜帶初始時及上一次重載時的參數),默認 false
列表展示時直接搜索所有數據渲染在頁面中,實現搜索功能時在后端需要使用動態SQL語句,將搜索條件寫在SQL搜索中,搜索條件為空時顯示所有數據
表格重載
table.reload('currentTableId', {
url: '/api/training/page'
,where: {
train_date:train_date
} //設定異步數據接口的額外參數
});
SQL語句
<select id="select" resultType="com.manager.entity.Training">
select * from y_training
<where>
<if test="train_date!=null">
train_date=#{train_date}
</if>
</where>
</select>