您好,登錄后才能下訂單哦!
Layui實現帶查詢條件的分頁?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
{include file="../../../application/admin/view/public/head" /} <div class="page-container p10"> <form class="layui-form " method="post" id="pageListForm"> <div class="layui-input-inline w150"> <div class="layui-btn-group"> <a data-full="1" data-href="{:url('addBanner')}" class="layui-btn layui-btn-primary j-iframe"><i class="layui-icon"></i>添加廣告</a> </div> </div> <div class="layui-input-inline w150"> <select name="vt_id" class="vt_id"> <option value="">視頻類型</option> {foreach name='subject' item='v'} <option value="{$v['vt_id']}" >{$v['vt_name']}</option> {/foreach} </select> </div> <div class="layui-input-inline w150"> <select name="b_targetType" class="b_targetType"> <option value="">是否跳出</option> <option value="1">是</option> <option value="2">否</option> </select> </div> <div class="layui-input-inline"> <input type="text" autocomplete="off" placeholder="請輸入搜索條件" id="content" class="layui-input" name="b_title" value=""> </div> <a class="layui-btn mgl-20 .j-kaka" id="query"> 查詢</a> <table class="layui-table" lay-size="sm"> <thead> <tr > <th width="25">ID</th> <th width="50">分類</th> <th width="100">對應視頻</th> <th width="40">縮略圖</th> <th width="80">點擊url</th> <th width="30">排序</th> <th width="100">展示類型</th> <th width="100">是否跳出2是1否</th> <th width="100">標題</th> <th width="100">內容頁模版</th> <th width="100">鏈接列表</th> <th width="130">操作</th> </tr> </thead> <tbody id="tab_list"> </tbody> </table> </form> </div> <div id="pages" class="center"></div> {include file="../../../application/admin/view/public/foot" /} <script type="text/javascript"> window.οnlοad= function () { loadData() //請求數據 getPage() //分頁操作 } var page=1; //設置首頁頁碼 var limit=3; //設置一頁顯示的條數 var total; //總條數 function loadData(){ $.ajax({ type:"post", url:"{url(Banner/index)}",//對應controller的URL async:false, dataType: 'json', data:{ "page_index":page, "page_size":limit, }, success:function(ret){ total=ret.total_count; var data1=ret.data; var html= ''; for(var i=0;i<data1.length;i++){ html+='<tr>'; html+='<td>'+ data1[i].b_id +'</td>'; html+='<td>'+ data1[i].b_id +'</td>'; html+='<td>'+ data1[i]['banner_vs_video_name']['vi_title'] +'</td>'; html+='<td>'+ data1[i]['b_thumbnailUrl'] +'</td>'; html+='<td>'+ data1[i]['b_linkUrl'] +'</td>'; html+='<td>'+ data1[i]['b_sort'] +'</td>'; html+='<td>'+ data1[i]['b_showType'] +'</td>'; html+='<td>'+ data1[i]['b_targetType'] +'</td>'; html+='<td>'+ data1[i]['b_title'] +'</td>'; html+='<td>'+ data1[i]['b_slaveTitle'] +'</td>'; html+='<td>'+ data1[i]['b_linkUrlList']+'</td>'; html+='<td>'; html+='<a class="layui-badge-rim j-iframe" data-full="1" data-href='+ROOT_PATH+'/index.php/admin/banner/editBanner?b_id='+data1[i]['b_id']+' href="javascript:;" title="編輯">編輯</a>'; html+='<a class="layui-badge-rim j-tr-del del" data-href='+ROOT_PATH+'/index.php/admin/banner/delBanner?b_id='+data1[i]['b_id']+' href="javascript:;" title="刪除">刪除</a>'; html+='</td>'; html+='</tr>'; } $("#tab_list").html(html); } }); } // 查詢 $('#query').click(function(){ var content = $('#content').val(); var vt_id = $('.vt_id').val(); var b_targetType = $('.b_targetType').val(); if(!content && !vt_id && !b_targetType){ layer.msg('查詢條件不能為空'); return false } $.ajax({ type:"post", url:"{url(Banner/index)}",//對應controller的URL async:false, dataType: 'json', data:{ "page_index":page, "page_size":limit, "b_title":content, "vt_id":vt_id, "b_targetType":b_targetType }, success:function(ret){ total=ret.total_count; getPage(); var data1=ret.data; var html= ''; for(var i=0;i<data1.length;i++){ html+='<tr>'; html+='<td>'+ data1[i].b_id +'</td>'; html+='<td>'+ data1[i].b_id +'</td>'; html+='<td>'+ data1[i]['banner_vs_video_name']['vi_title'] +'</td>'; html+='<td>'+ data1[i]['b_thumbnailUrl'] +'</td>'; html+='<td>'+ data1[i]['b_linkUrl'] +'</td>'; html+='<td>'+ data1[i]['b_sort'] +'</td>'; html+='<td>'+ data1[i]['b_showType'] +'</td>'; html+='<td>'+ data1[i]['b_targetType'] +'</td>'; html+='<td>'+ data1[i]['b_title'] +'</td>'; html+='<td>'+ data1[i]['b_slaveTitle'] +'</td>'; html+='<td>'+ data1[i]['b_linkUrlList']+'</td>'; html+='<td>'; html+='<a class="layui-badge-rim j-iframe" data-full="1" data-href='+ROOT_PATH+'/index.php/admin/banner/editBanner?b_id='+data1[i]['b_id']+' href="javascript:;" title="編輯">編輯</a>'; html+='<a class="layui-badge-rim j-tr-del del" data-href='+ROOT_PATH+'/index.php/admin/banner/delBanner?b_id='+data1[i]['b_id']+' href="javascript:;" title="刪除">刪除</a>'; html+='</td>'; html+='</tr>'; } $("#tab_list").html(html); } }); }); function getPage(){ layui.use('laypage', function(){ var laypage = layui.laypage , layer = layui.layer; laypage.render({ elem: 'pages' ,count: total //數據總數,從服務端得到 ,limit:limit ,jump: function(obj, first){ page=obj.curr; //改變當前頁碼 limit=obj.limit; if(!first){ loadData() } } }); }); } // 點擊刪除 $(document).on('click','.del',function(){ var that = $(this), href = !that.attr('data-href') ? that.attr('href') : that.attr('data-href'); layer.confirm('刪除之后無法恢復,您確定要刪除嗎?', {title:false, closeBtn:0}, function(index){ if (!href) { layer.msg('請設置data-href參數'); return false; } $.get(href, function(res){ layer.msg(res.msg); if (res.code == 1) { that.parents('tr').remove(); } }); layer.close(index); }); return false; }) /** * 更改數據順序 */ layui.use('laypage', function(){ var laypage = layui.laypage , layer = layui.layer, $ = layui.$; $(document).on('blur','.sort',function(){ var that = $(this), b_sort = that.val(); var b_id = that.attr('b_id'); $.post("{:url('banner/editSort')}",{b_sort:b_sort,b_id:b_id},function(res){ if(res == 1){ loadData() } }); }) }); </script> </body> </html>
這個業務只有一個問題那就是button,我們需要把button的標簽換了,換成a標簽
還有一個點就是在點擊查詢后,獲取的數據是根據條件查的,在把分頁初始化一次即可
看完上述內容,你們掌握Layui實現帶查詢條件的分頁的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。