layui數(shù)據(jù)表格實(shí)現(xiàn)重載數(shù)據(jù)表格功能(搜索功能)
layui數(shù)據(jù)表格實(shí)現(xiàn)重載數(shù)據(jù)表格功能,以搜索功能為例
- 加載數(shù)據(jù)表格
- 實(shí)現(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ù)選項(xiàng)
});
官方的文檔已經(jīng)把方法說的很明白了,下面展示實(shí)例用法(HTML部分依照官方文檔,不用修改)
layui.use('table', function () {
var table = layui.table;
table.render({
// 表格容器ID
elem: '#ware_info'
// 表格ID,必須設(shè)置,重載部分需要用到
, id: 'tableOne'
// 數(shù)據(jù)接口鏈接
, url: "異步請(qǐng)求數(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: '序號(hào)', 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',}
]]
});
});
實(shí)現(xiàn)搜索功能和數(shù)據(jù)表格重載
1、接口需求
需要有一個(gè)可以接收搜索條件并返回固定格式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: '序號(hào)', 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
}
});
});
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- LayUi中接口傳數(shù)據(jù)成功,表格不顯示數(shù)據(jù)的解決方法
- 解決layui數(shù)據(jù)表格table的橫向滾動(dòng)條顯示問題
- layui 表格的屬性的顯示轉(zhuǎn)換方法
- Layui實(shí)現(xiàn)數(shù)據(jù)表格默認(rèn)全部顯示(不要分頁)
- 解決Layui數(shù)據(jù)表格顯示無數(shù)據(jù)提示的問題
- layui 表格操作列按鈕動(dòng)態(tài)顯示的實(shí)現(xiàn)方法
- layui 實(shí)現(xiàn)表格某一列顯示圖標(biāo)
- 解決LayUI數(shù)據(jù)表格復(fù)選框不居中顯示的問題
- layui實(shí)現(xiàn)數(shù)據(jù)表格點(diǎn)擊搜索功能
- 基于layui實(shí)現(xiàn)高級(jí)搜索(篩選)功能
- Layui 數(shù)據(jù)表格批量刪除和多條件搜索的實(shí)例
- layui實(shí)現(xiàn)顯示數(shù)據(jù)表格、搜索和修改功能示例
相關(guān)文章
深入理解JavaScript中的宏任務(wù)和微任務(wù)機(jī)制
JavaScript中的任務(wù)分為宏任務(wù)和微任務(wù),它們的執(zhí)行順序會(huì)影響代碼的執(zhí)行結(jié)果。了解它們的機(jī)制可以幫助我們更好地理解事件循環(huán)和異步編程,避免出現(xiàn)一些意想不到的錯(cuò)誤2023-05-05
js es6系列教程 - 基于new.target屬性與es5改造es6的類語法
下面小編就為大家?guī)硪黄猨s es6系列教程 - 基于new.target屬性與es5改造es6的類語法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09
JAVASCRIPT下判斷IE與FF的比較簡(jiǎn)單的方式
在JAVASCRIPT當(dāng)中可以通過取當(dāng)前瀏覽器返回值來判斷當(dāng)前使用什么瀏覽器。2008-10-10
JavaScript SHA-256加密算法詳細(xì)代碼
這篇文章主要為大家詳細(xì)介紹了JavaScript SHA-256加密算法代碼,具有一定的參考價(jià)值,感興趣的朋友可以參考一下2016-10-10
js實(shí)現(xiàn)超酷的照片墻展示效果圖附源碼下載
這篇文章主要介紹了超酷的照片墻展示效果圖附源碼下載的相關(guān)資料,需要的朋友可以參考下2015-10-10
JavaScript單例模式實(shí)現(xiàn)自定義彈框
這篇文章主要為大家詳細(xì)介紹了JavaScript單例模式實(shí)現(xiàn)自定義彈框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
JavaScript實(shí)現(xiàn)JSON合并操作示例【遞歸深度合并】
這篇文章主要介紹了JavaScript實(shí)現(xiàn)JSON合并操作,結(jié)合實(shí)例形式分析了javascript基于遞歸深度實(shí)現(xiàn)json合并操作相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下2018-09-09

