Layui表格行工具事件與數據回填方法

今天小編就爲大家分享一篇Layui表格行工具事件與數據回填方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

使用Layui數據表格實現行工具事件與Layui表單彈框與數據回填具體步驟如下:

步驟一:佈置行工具欄樣式與數據表格初始化,代碼如下:

<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="compile">編輯</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="delete">刪除</a>
 </script>
var listEnquiryQuote;//詢價記錄表格
layui.use(['table','form','layer'], function () {
//詢價記錄表格初始化
      listEnquiryQuote = table.render({
        elem: '#EnquiryQuote'
       , method: 'post'
       , url: '/Purchase/AwaitQueryPrice/SelectEnquiry' //數據接口
       , id: 'idEnquiryQuote'
       , page: true //開啓分頁
       , cols: [[ //表頭
         { type: 'radio' }
        , { field: 'EnquiryID', title: '詢價ID', hide: true }
        , { field: 'SupplierName', title: '供應商名稱', width: 180 }
        , { field: 'CompanyName', title: '公司英文名', width: 180 }
        , { field: 'SupplierID', title: '供應商ID', hide: true }
        , { field: 'ProductName', title: '產品名稱', width: 90 }
        , { field: 'Model', title: '型號', width: 120 }
        , { field: 'Trademark', title: '原廠品牌', width: 90 }
        , { field: 'PrimaryNumber', title: '原廠料號', width: 90 }
        , { field: 'QualityName', title: '品質', width: 60 }
        , { field: 'QualityID', title: '品質ID', hide: true }
        , { field: 'UnitName', title: '單位', width: 60 }
        , { field: 'UnitID', title: '單位ID', hide: true }
        , { field: 'FPackaging', title: '封裝', width: 90 }
        , { field: 'BPackaging', title: '包裝', width: 60 }
        , { field: 'DateCodeS', title: '生產日期', width: 105 }
        , { field: 'Describe', title: '描述', width: 150 }
        , { field: 'DeliveryTime', title: '貨期', width: 60 }
        , { field: 'MinOrder', title: '最小訂購量', width: 105 }
        , { field: 'QuantityDemanded', title: '需求量', width: 80 }
        , { field: 'TaxPoint', title: '稅點', width: 60 }
        , { field: 'Quote', title: '報價', width: 70 }
        , { field: 'EnquiryDateS', title: '詢價日期', width: 105 }
        , { field: 'AdoptQuantity', title: '採納量', width: 80 }
        , { fixed: 'right', title: '操作', toolbar: '#barDemo2', width: 120 }
       ]]
        , limit: 10
        , response: {
          statusName: 'success' //規定數據狀態的字段名稱,默認:code
         , statusCode: true //規定成功的狀態碼,默認:0
         , countName: 'totalRows' //規定數據總數的字段名稱,默認:count
        }
        , request: {
          pageName: 'curPage' //頁碼的參數名稱,默認:page
         , limitName: 'pageSize'
        }
      });
});

效果圖如下:

步驟二:監聽行點擊事件:

layui.use(['table','form','layer'], function () {
//監聽詢價記錄行工具事件
      table.on('tool(EnquiryQuote)', function (obj) {
        var data = obj.data;
        //修改
        if (obj.event === 'compile') {
          if (data.AdoptQuantity == null || data.AdoptQuantity == 0) {
            //彈出修改詢價記錄模態框
            layer.open({
              type: 1,
              title: '修改詢價記錄',
              area: ['950px', '600px'],
              content: $('#UpdateEnquiry'), //這裏content是一個DOM,注意:最好該元素要存放在body最外層,否則可能被其它的相對元素所影響
            });
          } else {
            layer.msg('已有采購單採納該詢價,不得編輯!', { icon: 0 });
          }
          //重置
          $("#reset4").click(function () {
            //數據回填
            form.val("UpdateEnquiry", data);
            form.val("UpdateEnquiry", {
              "DateCode": data.DateCodeS
            })
            if (data.SupplierID != null) {
              //給表單賦值
              form.val("UpdateEnquiry", {
                "State": "true"
              })
            } else {
              //給表單賦值
              form.val("UpdateEnquiry", {
                "State": ""
              })
            }
          });
          $("#reset4").click();
    } 
});

應注意的表單必須有layui-form類與lay-filter屬性,本文獻lay-filter屬性值爲UpdateEnquiry,可自定義

把回填事件寫入重置按鈕點擊事件這樣設置的好處是在點擊重置是在點擊重置時可以重新回填數據,可以給用戶選擇的空間,效果圖如下:

以上這篇Layui表格行工具事件與數據回填方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持神馬文庫。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章