Jquery EasyUI datagrid数据库分页
生活随笔
收集整理的這篇文章主要介紹了
Jquery EasyUI datagrid数据库分页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.前端請求:
function loadRefProj(searchInput) {$('#projreftable').datagrid({url: 'DataServer/SilentContractProjectBatchHandler.ashx',columns: [[{ field: "Wbs號", title: "項目號", align: "center", width: 200 },{ field: "Wbs名稱", title: "項目名稱", align: "center", width: 450},{title: '', field: "Ref", align: "center", width: 100, formatter: function (value, rec, index) {return '<button οnclick="sureRefProj(\'' + index + '\');$(this).parent().click();return false;">引用</button>';}}]],pageSize: 10,pagination: true,pageList: [10, 20, 30, 40, 50],queryParams: { "action": "queryRefProj", "searchInput": searchInput },onDblClickRow: function (index, row) {sureRefProj(index);}});getPage($('#projreftable'));}function getPage($table) {var pager = $table.datagrid("getPager");pager.pagination({beforePageText: '第',afterPageText: '頁 共{pages}頁',displayMsg: '共{total}條', //當前顯示{from}-{to}條 }); }
2.后臺接收請求:
case "queryRefProj":{string searchInput = context.Request.Params["searchInput"] ?? "";int page = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;int size = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;context.Response.Write(QueryRefProj(searchInput, page, size));}string QueryRefProj(string searchInput, int page, int size) {DataTable refProjDt = dal.GetRefProj(page,size,searchInput);if (refProjDt != null && refProjDt.Rows.Count > 0){int count = dal.GetRefProjCount(searchInput);StringBuilder sbJson = new StringBuilder();sbJson.Append("{\"rows\":");sbJson.Append(JsonConvert.SerializeObject(refProjDt, Newtonsoft.Json.Formatting.Indented));sbJson.Append(",\"total\":");sbJson.Append(count + "}");return sbJson.ToString();}return "[]"; }
?3.數據庫請求語句:
SELECT TOP @size Wbs號,Wbs名稱 FROM (SELECT TOP @size*@page Wbs號,Wbs名稱 FROM Wbs結構表 @condition ORDER BY Wbs號) DERIVEDTBL ORDER BY Wbs號 DESC public DataTable GetRefProj(int page, int size, string queryInput = null){string strSql = "SELECT TOP {0} Wbs號,Wbs名稱 FROM (SELECT TOP {1} Wbs號,Wbs名稱 FROM Wbs結構表 {2} ORDER BY Wbs號) DERIVEDTBL ORDER BY Wbs號 DESC ";if (!string.IsNullOrWhiteSpace(queryInput)){queryInput = string.Format(" where Wbs號 like '%{0}%' or Wbs名稱 like '%{0}%'", queryInput);}strSql = string.Format(strSql, size, page * size, queryInput ?? "");return DaoService.GetDBDataSet(strSql, null).Tables[0];}public int GetRefProjCount(string queryInput = null){string strSql = SqlUtil.GetSelSql("COUNT(*)", "Wbs結構表");queryInput = queryInput ?? "";strSql = string.Format(strSql, string.Format(" where Wbs號 like '%{0}%' or Wbs名稱 like '%{0}%'", queryInput));return Convert.ToInt32(DaoService.ExecuteScalar(CommandType.Text, strSql, null));}?
轉載于:https://www.cnblogs.com/Med1tator/p/7479301.html
總結
以上是生活随笔為你收集整理的Jquery EasyUI datagrid数据库分页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity教程之-UGUI美术字体的制作
- 下一篇: Spring(二)IOC底层实现原理