Layui表格列添加超鏈接


記錄一下,需要用到templet屬性,也就是自定義列模板

參考代碼:

{ field: 'oddNumbers', width: 180, title: '單號', sort: true, fixed: 'left', templet: addLink },

addLink是個方法

function addLink(d) {
  var addLink = d.oddNumbers;
   if ('' == addLink || null == addLink || undefined == addLink) {
        return '';
   }
   if (addLink.length > 0) {                  
        return '<a class="layui-table-link" href="javascript:void(0);" lay-event="link">' + d.oddNumbers + '</a>';                  
   }
}        

layui 2.2.5 開始,templet 開始支持函數形式,函數返回一個參數 d,包含接口返回的所有字段和數據。

參考鏈接https://www.layui.com/demo/table/style.html  https://www.layui.com/doc/modules/table.html#templet

這樣界面就有超鏈接了,如下圖

一般鏈接會打開一個tabs或彈窗或者其它,我用的彈窗,監聽表格行,獲取點擊行數據,如下

 table.on('tool(pcList)', function (obj) {
      var checkStatus = obj.data;
      var url = checkStatus.oddNumbers;
      url = encodeURIComponent(url);
      console.log(checkStatus.oddNumbers);//單號
      layer.open({
           type: 2,
           title: '賬票詳細',
           shadeClose: true,
           shade: 0.8,
           area: ['60%', '90%'],
           content: 'newList.html?'+url 
      });
 });

這樣就ok了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM