JQuery Datatables(二)

來源:互聯網
上載者:User

標籤:

前篇講到了Datatables的基本用法,連結地址:http://www.cnblogs.com/wumian1360/p/4263129.html

今天來實現5,6,7三點。

其實Datatables控制項本身就已經帶了分頁屬性,排序屬性和篩選屬性,分別是:bPaginate,bSort,bFilter,我們只需要將這三個屬性設定為true,那麼在Ajax重新整理的時候就會在Query String Parameters有參數了。具體如下:

 1 sEcho:1                //操作次數,具體用途不是很清楚 2 iColumns:2            //Datatables的列總數 3 sColumns:Id,Name    //列名 4 iDisplayStart:0        //分頁開始頁碼 5 iDisplayLength:10    //每頁顯示行數 6 mDataProp_0:Id        //第一列映射欄位 7 sSearch_0:            //第一列篩選內容 8 bRegex_0:false        //該欄位是否使用正則 9 bSearchable_0:true    //是否使用篩選功能10 bSortable_0:false    //是否可以排序11 mDataProp_1:Name    //第一列映射欄位12 sSearch_1:            //第一列篩選內容13 bRegex_1:false        //該欄位是否使用正則14 bSearchable_1:true    //是否使用篩選功能15 bSortable_1:true    //是否可以排序16 sSearch:            //全文篩選17 bRegex:false        //是否使用正則18 iSortCol_0:0        //當前排序列索引(第一列)19 sSortDir_0:asc        //排序為升序20 iSortingCols:1        //排序的列數21 _:1423311150960
Http請求參數

功能很強大啊,什麼都有了,那麼只需要建立對象來接受處理這些參數,然後利用對象去分別做分頁,排序和篩選就可。

該處理對象類用了“冠軍”的代碼,具體連結:http://www.cnblogs.com/haogj/archive/2011/03/21/1990595.html

有了該對象,那麼可以在具體的Controller中處理了。

代碼如下:

 1 public JsonResult Get() 2 { 3     DataTablesRequest parm = new DataTablesRequest(this.Request);    //處理對象 4     int totalCount = 0;         5     int start = parm.iDisplayStart;    //頁索引 6     int length = parm.iDisplayLength;    //頁行數 7     string order = string.Empty;    //排序 8  9     //擷取排序10     if (parm.SortColumns.Count() > 0)11     {12         string sortField = parm.Columns[parm.SortColumns[0].Index].Name;13         string sort = parm.SortColumns[0].Direction.ToString();14         order = sortField + " " + sort;15     }16     17     string strQuery = parm.Search;18     string[] fields = new string[parm.iColumns];19     //此處可以建立對象來封裝全文檢索查詢欄位內容,簡單,個人去實現即可20     21     var list=XXXX.LoadPage(start,length,out totalCount,order,strQuery,fields)22     23     return Json(new { aaData = list, iTotalRecords = totalCount, iTotalDisplayRecords = totalCount },24                 JsonRequestBehavior.AllowGet);25 }
Ctroller操作

 

JQuery Datatables(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.