Bootstrap Table使用整理(五)之分頁組合查詢
推薦閱讀:
Bootstrap Table使用整理(一) http://www.dbjr.com.cn/article/115789.htm
Bootstrap Table使用整理(二) http://www.dbjr.com.cn/article/115791.htm
Bootstrap Table使用整理(三) http://www.dbjr.com.cn/article/115795.htm
Bootstrap Table使用整理(四)之工具欄 http://www.dbjr.com.cn/article/115798.htm
一、分頁組合查詢
/* * data-pagination 指定是否啟用分頁 * data-page-list 指定分頁的頁數(shù)據(jù)量數(shù)組 '[5,10]' * data-side-pagination 指定分頁是否是服務端(server)/客戶端(client) * 特別說明: * 客戶端,請求參數(shù): * search:文本框內(nèi)容,在文本框內(nèi)容改變是自動提交請求 * order: 排序方式 * sort:排序列名 * offset:劃過條數(shù) * limit:要獲取的數(shù)據(jù)的條數(shù) * */ var $table1= $('#table1').bootstrapTable({ columns: [ { field: 'sno', title: '學生編號',sortable:true }, { field: 'sname', title: '學生姓名' }, { field: 'ssex', title: '性別' }, { field: 'sbirthday', title: '生日' }, { field: 'class', title: '課程編號' }, ], url: '@Url.Action("GetStuList", "DataOne")', pagination: true, sidePagination: 'server', pageList:[5,10,20,50], queryParams: function (params) { params.name = '張三豐'; //特別說明,返回的參數(shù)的值為空,則當前參數(shù)不會發(fā)送到服務器端 //這種指定請求參數(shù)的方式和datatables控價類似 params.sex = $('input[name="sex"]:checked').val(); return params; } }); //刷新方法 $('#heartBtn').click(function () { $table1.bootstrapTable('refresh'); }); [html] view plain copy print? <table id="table1" data-classes="table table-hover " data-search="true" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-toolbar="#toolbar"></table> <div id="toolbar"> <div class="btn-group"> <button class="btn btn-default"> <i class="glyphicon glyphicon-plus"></i> </button> <button class="btn btn-default"> <i class="glyphicon glyphicon-heart" id="heartBtn"></i> </button> <button class="btn btn-default"> <i class="glyphicon glyphicon-trash"></i> </button> </div> <div class="form-group"> <label class="control-label">性別:</label> <label class="radio-inline"> <input type="radio" name="sex" value="男" /> 男 </label> <label class="radio-inline"> <input type="radio" name="sex" value="女" /> 女 </label> </div> </div>
2.服務端代碼處理
public JsonResult GetStuList(string sex, string search, string sort, string order, int offset, int limit) { var query = _Context.Student.AsQueryable(); if (string.IsNullOrEmpty(sex) == false) query = query.Where(q => q.Ssex == sex); if (string.IsNullOrEmpty(search) == false) query = query.Where(q => q.Sno.Contains(search) || q.Sname.Contains(search)); //排序 if (sort == "sno") { if (order == "asc") query = query.OrderBy(q => q.Sno); else query = query.OrderByDescending(q => q.Sno); } else query = query.OrderBy(q => q.Sbirthday); int total = query.Count(); var list = query.Skip(offset).Take(limit).ToList(); return Json(new { rows = list, total = total }); }
以上所述是小編給大家介紹的Bootstrap Table使用整理(五)之分頁組合查詢,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
關于BootstrapTable 導出數(shù)據(jù)的問題最終解決方案
這篇文章主要介紹了BootstrapTable 導出數(shù)據(jù)的問題,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03文本框只能輸入數(shù)字的實現(xiàn)方法(兼容IE火狐)
下面小編就為大家?guī)硪黄谋究蛑荒茌斎霐?shù)字的實現(xiàn)方法(兼容IE火狐)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06JavaScript forEach 方法跳出循環(huán)的操作方法
這篇文章主要介紹了JavaScript forEach 方法跳出循環(huán)的操作方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01