這篇文章主要為大家展示了“在Layui中操作數(shù)據(jù)表格給指定單元格添加事件的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“在Layui中操作數(shù)據(jù)表格給指定單元格添加事件的示例分析”這篇文章吧。

當(dāng)我們在操作數(shù)據(jù)表格的時候,并不是一定要點擊表格工具欄中的“查看”按鈕,來進(jìn)行查看,而是點擊某一特定的列來進(jìn)行某些數(shù)據(jù)查看。例如下圖這樣。

這就涉及到表格的自定義事件。代碼如下:
<table id='task-list' lay-filter='task-list'></table> // 需要渲染的表格
var tableInit = function (data) {
table.render({
elem: '#task-list'
, height: 472
, title: '決策場景信息'
, limit: data.length + 1
, page: {
theme: '#1E9FFF',
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定義分頁布局
, limit: 10
, groups: 1 //只顯示 1 個連續(xù)頁碼
, first: false //不顯示首頁
, last: false //不顯示尾頁
}
, cols: [[
{field: 'id', title: '序號', width: 60, style: 'font-size: 12px; color: #666'},
{field: 'modelNum', title: '場景模型編號', style: 'font-size: 12px; color: #666'},
{field: 'modelName', title: '場景模型名稱', style: 'font-size: 12px; color: #666'},
{field: 'taskNum', title: '當(dāng)前任務(wù)編號', style: 'font-size: 12px; color: #666'},
{field: 'taskLevel', title: '當(dāng)前任務(wù)階段', width: 150, templet: "#level", style: 'font-size: 12px; color: #666'},
{field: 'report', title: '報告', width: 60, event: 'viewReport', templet: "#reportID", style: 'font-size: 12px; color: #666; cursor:pointer'},
// 這里設(shè)置event,事件名稱自定義。
{field: 'history', title: '歷史任務(wù)', width: 100, style: 'font-size: 12px; color: #666'},
{
fixed: 'right',
title: '操作',
width: 100,
toolbar: "#table-linetoolbar",
align: 'center',
style: 'font-size: 12px; color: #666'
}
]]
, cellMaxWidth: 100
, parseData: function (res) {
return res;
}
, data: data
, id: 'task-list'
});
table.on('tool(task-list)', function (obj) {
let event = obj.event;
if (event === "viewReport"){
// 處理你的業(yè)務(wù)邏輯
}
}這樣就可以給某特定列設(shè)置自定義事件了。
以上是“在Layui中操作數(shù)據(jù)表格給指定單元格添加事件的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
本文題目:在Layui中操作數(shù)據(jù)表格給指定單元格添加事件的示例分析-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://chinadenli.net/article12/pdegc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、軟件開發(fā)、用戶體驗、企業(yè)建站、響應(yīng)式網(wǎng)站、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)