推薦閱讀:
Bootstrap Table使用整理(一) https://www.jb51.net/article/115789.htm
Bootstrap Table使用整理(二) https://www.jb51.net/article/115791.htm
Bootstrap Table使用整理(三) https://www.jb51.net/article/115795.htm
Bootstrap Table使用整理(四)之工具欄 https://www.jb51.net/article/115798.htm
一、分頁組合查詢
/*
* data-pagination 指定是否啟用分頁
* data-page-list 指定分頁的頁數據量數組 '[5,10]'
* data-side-pagination 指定分頁是否是服務端(server)/客戶端(client)
* 特別說明:
* 客戶端,請求參數:
* search:文本框內容,在文本框內容改變是自動提交請求
* order: 排序方式
* sort:排序列名
* offset:劃過條數
* limit:要獲取的數據的條數
*
*/
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 = '張三豐';
//特別說明,返回的參數的值為空,則當前參數不會發送到服務器端
//這種指定請求參數的方式和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使用整理(五)之分頁組合查詢,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。