国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

layui數(shù)據(jù)表格實現(xiàn)重載數(shù)據(jù)表格功能(搜索功能)

2024-05-06 15:36:31
字體:
來源:轉載
供稿:網友

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ù)選項});

官方的文檔已經把方法說的很明白了,下面展示實例用法(HTML部分依照官方文檔,不用修改)

layui.use('table', function () {    var table = layui.table;    table.render({      // 表格容器ID      elem: '#ware_info'      // 表格ID,必須設置,重載部分需要用到      , id: 'tableOne'      // 數(shù)據(jù)接口鏈接      , url: "異步請求數(shù)據(jù)接口地址"      // 附加參數(shù),post token      , where: {'token': token}      , method: 'post'      // 分頁 curr起始頁,groups連續(xù)顯示的頁碼,默認每頁顯示的條數(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、接口需求
需要有一個可以接收搜索條件并返回固定格式json文件的數(shù)據(jù)接口。

2、注意要提前導入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,必須設置,重載部分需要用到      , id: 'tableOne'      // 數(shù)據(jù)接口鏈接      , url: "你的異步數(shù)據(jù)接口地址"      // 附加參數(shù),post token      , where: {'token': token}      , method: 'post'      // 分頁 curr起始頁,groups連續(xù)顯示的頁碼,默認每頁顯示的條數(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        }      });    });            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 囊谦县| 玉田县| 门源| 肥城市| 临江市| 通化市| 洪雅县| 卓资县| 博湖县| 齐齐哈尔市| 酒泉市| 和平县| 亚东县| 和硕县| 商洛市| 呈贡县| 绵竹市| 祁东县| 宁远县| 东安县| 腾冲县| 奈曼旗| 且末县| 静安区| 砀山县| 三原县| 镇赉县| 武强县| 勃利县| 雷州市| 马龙县| 嘉祥县| 昆山市| 澎湖县| 靖边县| 宁化县| 南城县| 美姑县| 南充市| 达日县| 长岛县|