改變頭部原理:刪除原來(lái)表格, 重新建立DOM元素, 重新加載table,實(shí)現(xiàn)表頭改變
為樂(lè)亭等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及樂(lè)亭網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、樂(lè)亭網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!明白了原理, 我相信大家都能寫(xiě)出來(lái)了, table.reload(ID, options)目前好像還不支持cons的基礎(chǔ)函數(shù)變動(dòng),只能使用其他方式了,簡(jiǎn)單暴力,哈哈哈哈哈哈哈哈嗝??!
下面是示例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="static/layui/css/layui.css" rel="external nofollow" > </head> <body> <div id="myTable"> <table id="demo" lay-filter="test"></table> </div> <button id="buttonChangeTitle" class="layui-btn ">點(diǎn)擊改變表頭</button> <script type="text/javascript" src="static/layui/layui.js" charset="utf-8"></script> <script> layui.use(['element', 'jquery', 'table'], function () { var $ = layui.jquery , table = layui.table , element = layui.element; //Tab的切換功能,切換事件監(jiān)聽(tīng)等,需要依賴(lài)element模塊 var data = [ { "id": 10000, "username": "user-0", "sex": "女", "city": "城市-0", "sign": "簽名-0", "experience": 255, "logins": 24, "wealth": 82830700, "classify": "作家", "score": 57 }, { "id": 10001, "username": "user-1", "sex": "男", "city": "城市-1", "sign": "簽名-1", "experience": 884, "logins": 58, "wealth": 64928690, "classify": "詞人", "score": 27 }, { "id": 10002, "username": "user-2", "sex": "女", "city": "城市-2", "sign": "簽名-2", "experience": 650, "logins": 77, "wealth": 6298078, "classify": "醬油", "score": 31 }, { "id": 10003, "username": "user-3", "sex": "女", "city": "城市-3", "sign": "簽名-3", "experience": 362, "logins": 157, "wealth": 37117017, "classify": "詩(shī)人", "score": 68 }, { "id": 10004, "username": "user-4", "sex": "男", "city": "城市-4", "sign": "簽名-4", "experience": 807, "logins": 51, "wealth": 76263262, "classify": "作家", "score": 6 }, { "id": 10005, "username": "user-5", "sex": "女", "city": "城市-5", "sign": "簽名-5", "experience": 173, "logins": 68, "wealth": 60344147, "classify": "作家", "score": 87 }, { "id": 10006, "username": "user-6", "sex": "女", "city": "城市-6", "sign": "簽名-6", "experience": 982, "logins": 37, "wealth": 57768166, "classify": "作家", "score": 34 }, { "id": 10007, "username": "user-7", "sex": "男", "city": "城市-7", "sign": "簽名-7", "experience": 727, "logins": 150, "wealth": 82030578, "classify": "作家", "score": 28 }, { "id": 10008, "username": "user-8", "sex": "男", "city": "城市-8", "sign": "簽名-8", "experience": 951, "logins": 133, "wealth": 16503371, "classify": "詞人", "score": 14 }, { "id": 10009, "username": "user-9", "sex": "女", "city": "城市-9", "sign": "簽名-9", "experience": 484, "logins": 25, "wealth": 86801934, "classify": "詞人", "score": 75 }] var title = [ //表頭 {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left'} , {field: 'username', title: '用戶(hù)名', width: 80} , {field: 'sex', title: '性別', width: 80, sort: true} , {field: 'city', title: '城市', width: 80} , {field: 'sign', title: '簽名', width: 177} , {field: 'experience', title: '積分', width: 80, sort: true} , {field: 'score', title: '評(píng)分', width: 80, sort: true} , {field: 'classify', title: '職業(yè)', width: 80} , {field: 'wealth', title: '財(cái)富', sort: true} ] var title2 = [ //表頭 {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left'} , {field: 'username', title: '用戶(hù)名', width: 80} , {field: 'wealth', title: '財(cái)富', sort: true} ] //第一個(gè)實(shí)例 var tableIns = table.render({ elem: '#demo' , id: 'demoTest' , height: 312 // ,url: '/demo/table/user/' //數(shù)據(jù)接口 , data: data , page: true //開(kāi)啟分頁(yè) , cols: [title] }); $("#buttonChangeTitle").on("click", function () { $("#myTable").empty(); $("#myTable").append('<table id="demo"></table>'); //第一個(gè)實(shí)例 var tableIns2 = table.render({ elem: '#demo' , id: 'demoTest' , height: 312 // ,url: '/demo/table/user/' //數(shù)據(jù)接口 , data: data , page: true //開(kāi)啟分頁(yè) , cols: [title2] }); }) }) </script> </body> </html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
文章標(biāo)題:layuitable動(dòng)態(tài)表頭改變表格頭部重新加載表格的方法-創(chuàng)新互聯(lián)
新聞來(lái)源:http://www.rwnh.cn/article44/copoee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、外貿(mào)建站、網(wǎng)站維護(hù)、自適應(yīng)網(wǎng)站、云服務(wù)器、小程序開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容