1. 程式人生 > 其它 >Layui---table表單查詢過載

Layui---table表單查詢過載

//查詢輸入框

<div class="layui-card-body">
            <!--<form class="layui-form" action="">-->
                <div class="layui-form-item">
                    <label class="layui-form-label">學生姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="stuname" name="name" lay-verify="" value="<?php echo $_GET['name'];?>" placeholder="請輸入" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">身份證</label>
                    <div class="layui-input-inline">
                        <input type="text" id="shenfenzheng" name="shenfenzheng" lay-verify="" value="<?php echo $_GET['身份證'];?>" placeholder="請輸入" autocomplete="off" class="layui-input">
                    </div>       
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query" id="userQuery">
                    <i class="layui-icon layui-icon-search"></i>
                    查詢
                    </button>  
                </div>
            <!--</form>-->
        </div>

//表格

<div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
 </div>

//功能程式碼

   // 表格渲染
            table.render({
                elem: '#dataTable',
                url: MODULE_PATH + 'student_index.php',
                page: true,
                cols: cols,
                cellMinWidth: 100,
                skin: 'line',
                toolbar: '#toolbar',
            });
            // 查詢功能,表格過載
            $(document).on('click','#userQuery',function(){
                var serch=$('#stuname')
                var shenfen=$('#shenfenzheng')
                table.reload('dataTable',{
                    where:{
                        name:serch.val(),
                        shenfenzheng:shenfen.val()
                    },
                    page:{
                        curr:1
                    }
                })
            })