layui數(shù)據(jù)表格實現(xiàn)重載數(shù)據(jù)表格功能(搜索功能)
layui數(shù)據(jù)表格實現(xiàn)重載數(shù)據(jù)表格功能,以搜索功能為例
- 加載數(shù)據(jù)表格
- 實現(xiàn)搜索功能和數(shù)據(jù)表格重載
- 全部代碼
加載數(shù)據(jù)表格
按照layui官方文檔示例
HTML部分
<table id="demo" lay-filter="test"></table>
JavaScript部分
var table = layui.table;
//執(zhí)行渲染
table.render({
elem: '#demo' //指定原始表格元素選擇器(推薦id選擇器)
,height: 315 //容器高度
,cols: [{}] //設(shè)置表頭
//,…… //更多參數(shù)參考右側(cè)目錄:基本參數(shù)選項
});
官方的文檔已經(jīng)把方法說的很明白了,下面展示實例用法(HTML部分依照官方文檔,不用修改)
layui.use('table', function () {
var table = layui.table;
table.render({
// 表格容器ID
elem: '#ware_info'
// 表格ID,必須設(shè)置,重載部分需要用到
, id: 'tableOne'
// 數(shù)據(jù)接口鏈接
, url: "異步請求數(shù)據(jù)接口地址"
// 附加參數(shù),post token
, where: {'token': token}
, method: 'post'
// 分頁 curr起始頁,groups連續(xù)顯示的頁碼,默認(rèn)每頁顯示的條數(shù)
, page: {
layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
, curr: 1
, groups: 6
, limit: 20
}
, cols: [[
{fixed: 'lift', title: '序號', type: 'numbers', minWidth: 60, align: 'center',}
, {field: 'part', title: '類型', align: 'center', width: 120}
, {field: 'uid', title: 'UID', align: 'center', width: 200, sort: true, event: 'details', style: 'color: #0066CC; cursor:pointer;'}
, {field: 'quantity', title: '數(shù)量', width: 120, align: 'center', event: 'setNumber', style: 'color: #0066CC; cursor:pointer;'}
, {field: 'description', title: '描述', align: 'center', minWidth: 80}
, {field: 'disable', title: '狀態(tài)', sort: true, width: 80, align: 'center',}
]]
});
});
實現(xiàn)搜索功能和數(shù)據(jù)表格重載
1、接口需求
需要有一個可以接收搜索條件并返回固定格式j(luò)son文件的數(shù)據(jù)接口。
2、注意要提前導(dǎo)入layui的依賴模塊
JavaScript部分代碼如下:
// 執(zhí)行搜索,表格重載
$('#do_search').on('click', function () {
// 搜索條件
var send_name = $('#send_name').val();
var send_data = $('#send_data').val();
table.reload('tableOne', {
method: 'post'
, where: {
'token': token,
'send_name': send_name,
'send_data': send_data,
}
, page: {
curr: 1
}
});
});
全部代碼
HTML部分
<table class="layui-hide" id="ware_info" lay-filter="tableOne"></table>
JavaScript部分
// 加載表格
layui.use('table', function () {
var table = layui.table;
table.render({
// 表格容器ID
elem: '#ware_info'
// 表格ID,必須設(shè)置,重載部分需要用到
, id: 'tableOne'
// 數(shù)據(jù)接口鏈接
, url: "你的異步數(shù)據(jù)接口地址"
// 附加參數(shù),post token
, where: {'token': token}
, method: 'post'
// 分頁 curr起始頁,groups連續(xù)顯示的頁碼,默認(rèn)每頁顯示的條數(shù)
, page: {
layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
, curr: 1
, groups: 6
, limit: 20
}
, cols: [[
{fixed: 'lift', title: '序號', type: 'numbers', minWidth: 60, align: 'center',}
, {field: 'part', title: '類型', align: 'center', width: 120}
, {field: 'uid', title: 'UID', align: 'center', width: 200, sort: true, event: 'details', style: 'color: #0066CC; cursor:pointer;'}
, {field: 'quantity', title: '數(shù)量', width: 120, align: 'center', event: 'setNumber', style: 'color: #0066CC; cursor:pointer;'}
, {field: 'description', title: '描述', align: 'center', minWidth: 80}
, {field: 'disable', title: '狀態(tài)', sort: true, width: 80, align: 'center',}
]]
});
// 執(zhí)行搜索,表格重載
$('#do_search').on('click', function () {
// 搜索條件
var send_name = $('#send_name').val();
var send_data = $('#send_data').val();
table.reload('tableOne', {
method: 'post'
, where: {
'csrfmiddlewaretoken': token,
'send_name': send_name,
'send_data': send_data,
}
, page: {
curr: 1
}
});
});
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- LayUi中接口傳數(shù)據(jù)成功,表格不顯示數(shù)據(jù)的解決方法
- 解決layui數(shù)據(jù)表格table的橫向滾動條顯示問題
- layui 表格的屬性的顯示轉(zhuǎn)換方法
- Layui實現(xiàn)數(shù)據(jù)表格默認(rèn)全部顯示(不要分頁)
- 解決Layui數(shù)據(jù)表格顯示無數(shù)據(jù)提示的問題
- layui 表格操作列按鈕動態(tài)顯示的實現(xiàn)方法
- layui 實現(xiàn)表格某一列顯示圖標(biāo)
- 解決LayUI數(shù)據(jù)表格復(fù)選框不居中顯示的問題
- layui實現(xiàn)數(shù)據(jù)表格點擊搜索功能
- 基于layui實現(xiàn)高級搜索(篩選)功能
- Layui 數(shù)據(jù)表格批量刪除和多條件搜索的實例
- layui實現(xiàn)顯示數(shù)據(jù)表格、搜索和修改功能示例
相關(guān)文章
前端JavaScript實現(xiàn)大數(shù)據(jù)前后模糊搜索的方法詳解
這篇文章主要為大家詳細(xì)介紹了前端JavaScript實現(xiàn)大數(shù)據(jù)前后模糊搜索的四個常見方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2023-12-12

