溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Bootstrap Table使用整理(五)之分頁組合查詢

發(fā)布時(shí)間:2020-09-15 20:32:28 來源:腳本之家 閱讀:149 作者:天馬3798 欄目:web開發(fā)

推薦閱讀:

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 指定分頁的頁數(shù)據(jù)量數(shù)組 '[5,10]' 
* data-side-pagination 指定分頁是否是服務(wù)端(server)/客戶端(client) 
* 特別說明: 
* 客戶端,請(qǐng)求參數(shù): 
* search:文本框內(nèi)容,在文本框內(nèi)容改變是自動(dòng)提交請(qǐng)求 
* order: 排序方式 
* sort:排序列名 
* offset:劃過條數(shù) 
* limit:要獲取的數(shù)據(jù)的條數(shù) 
* 
*/ 
var $table1= $('#table1').bootstrapTable({ 
 columns: [ 
  { field: 'sno', title: '學(xué)生編號(hào)',sortable:true }, 
  { field: 'sname', title: '學(xué)生姓名' }, 
  { field: 'ssex', title: '性別' }, 
  { field: 'sbirthday', title: '生日' }, 
  { field: 'class', title: '課程編號(hào)' }, 
 ], 
 url: '@Url.Action("GetStuList", "DataOne")', 
 pagination: true, 
 sidePagination: 'server', 
 pageList:[5,10,20,50], 
 queryParams: function (params) { 
  params.name = '張三豐'; 
  //特別說明,返回的參數(shù)的值為空,則當(dāng)前參數(shù)不會(huì)發(fā)送到服務(wù)器端 
  //這種指定請(qǐng)求參數(shù)的方式和datatables控價(jià)類似 
  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.服務(wù)端代碼處理

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使用整理(五)之分頁組合查詢

以上所述是小編給大家介紹的Bootstrap Table使用整理(五)之分頁組合查詢,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI