layui獲取表格數據table的復選框checkbox的所有id


layui獲取表格數據table的復選框checkbox的所有id

用官方的lay-event測試一直無法獲取,所以用了這種方法

<button class="layui-btn"  onclick="getIds()">
    <i class="layui-icon"></i>獲取選中ID</button>
<table class="layui-hide" id="demo" lay-filter="test"></table>

<script>

 //獲取選中ID
    function getIds()
    {
        var checkStatus = layui.table.checkStatus('demo'); //demo 即為基礎參數 id 對應的值

        //console.log(checkStatus.data) //獲取選中行的數據即 多個行對象
        //console.log(checkStatus.data.length) //獲取選中行數量,可作為是否有選中行的條件
        //console.log(checkStatus.isAll ) //表格是否全選
        if (checkStatus.data.length>0) {
            var idsArray = [];
            for (var i = 0; i < checkStatus.data.length; i++) {
                idsArray.push(checkStatus.data[i].new_id);
            }
            var ids = idsArray.toString();
            // console.log(ids);
            layui.layer.alert(ids);
            $(".layui-form-checked").not('.header').parents('tr').remove();
        }
        else
        {
            layui.layer.alert("請至少選擇一行");
        }

    }


layui.use(['layer', 'table'], function(){
        var layer = layui.layer //彈層
            ,table = layui.table //表格

        //向世界問個好
        //layer.msg('Hello World');

        //執行一個 table 實例
        table.render({
            elem: '#demo'
            ,height: 420
            ,url: './list2_json' //數據接口
            ,title: '用戶表'
            ,page: true //開啟分頁
            ,toolbar: 'default' //開啟工具欄,此處顯示默認圖標,可以自定義模板,詳見文檔
            ,totalRow: true //開啟合計行
            ,cols: [ [ //表頭
                {type: '', fixed: 'left'}
                ,{field: 'new_id', title: 'ID', width:80, sort: true, fixed: 'left'}
                ,{field: 'new_title', title: '標題', width:300}
                ,{field: 'new_menu', title: '類別', width:120}
                ,{field: 'new_order', title: '排序', width:80}
                ,{field: 'new_time', title: '添加時間', width: 130}
            ]]
        });



    });
</script>

  


免責聲明!

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



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