在Jqgrid中使用WCF服务和asp.net自定义分页
本文关键字:asp net 自定义 分页 服务 WCF Jqgrid | 更新日期: 2023-09-27 17:49:15
这是我绑定Jqgrid的代码,在我的场景中,我正在获取25000条记录,这使得网格非常慢,所以我需要在Jqgrid中实现自定义分页,这样只有50条记录应该一次加载。
<script type="text/javascript">
$(document).ready(function () {
$("#TableDataGrid").jqGrid({
url: '/DataHandler.ashx?MethodName=TFNUserView&GroupNameQuery=<%=Master.GroupName %>&isadminCheck=<%=Master.Admin %>&isActiveCheck=<%=false %>',
datatype: "json",
colNames: ['ID', 'TFN', 'Group', 'Sub Group', 'Tactic', 'Sub Tactic', 'Micro Tactic',
'Campaign Name', 'Campaign Start Date', 'Campaign End Date', 'PCC',
'Segmentation', 'Vanity Description', 'Message', 'Notes', 'Organization', 'Product', 'Owner', 'Agency', ],
prmNames: { id: 'TFN' },
colModel: [
{
name: 'ID', index: 'ID', hidden: true,
editoptions: { disabled: true }, width: 80, "sortable": true, editable: true, sorttype: 'integer',
searchoptions: {
sopt: ['eq'], dataInit: function (elem) {
$(elem).height(21).width(40);
}
}, searchrules: { required: true }
},
{
name: 'TFN', index: 'TFN', key: true, edittype: 'select', formatter: 'showlink', width: 110,
formatoptions: { baseLinkUrl: 'TFNEdit.aspx' }, editable: true, sorttype: 'integer',
searchoptions: {
sopt: ['eq', 'ne'],
dataInit: function (elem) {
$(elem).height(21).width(60);
}
}, searchrules: { required: true }
},
{ name: 'TeamName', index: 'TeamName', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'LanguageGroupName', index: 'LanguageGroupName', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'TacticName', index: 'TacticName', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'SubtacticName', index: 'SubtacticName', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'MicrotacticName', index: 'MicrotacticName', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'MarketingCampaignName', index: 'MarketingCampaignName', width: 190, editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{
name: 'MarketingCampaignStartDate', index: 'MarketingCampaignStartDate', width: 190, editable: true, sorttype: 'date',
searchoptions: { sopt: ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] }, formatter: 'date', datefmt: 'm/d/Y', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' },
editoptions: {
size: 12, dataInit: function (elem) {
setTimeout(function () {
$(elem).datepicker({ showOn: 'button' });
}, 100);
}
}, searchrules: { required: true }
},
{
name: 'MarketingCampaignEndDate', index: 'MarketingCampaignEndDate', width: 190, editable: true, sorttype: 'date',
searchoptions: { sopt: ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] }, formatter: 'date', datefmt: 'm/d/Y', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' },
editoptions: {
size: 12, dataInit: function (elem) {
setTimeout(function () {
$(elem).datepicker({ showOn: 'button' });
}, 100);
}
}, searchrules: { required: true }
},
{ name: 'PCC', index: 'PCC', editable: true, sorttype: 'text', width: 190, searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'Segmentaion', index: 'Segmentaion', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'VanityDescription', index: 'VanityDescription', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'GeneralNotes', index: 'GeneralNotes', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'Notes', index: 'Notes', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'Organization', index: 'Organization', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true }, hidden: checkAdmin() },
{ name: 'Product', index: 'Product', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true }, hidden: checkAdmin() },
{ name: 'OwnerName', index: 'OwnerName', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } },
{ name: 'Agency', index: 'Agency', editable: true, sorttype: 'text', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] }, searchrules: { required: true } }
],
rowNum: 20,
rowList: [20, 100, 1000,10000],
pager: $('#DivPager'),
viewrecords: true,
loadonce: true,
sortable: true,
width: "100%",
autowidth: false,
shrinkToFit: false,
forceFit: false,
ignoreCase: true,
caption: "TFN User View"
});
$("#TableDataGrid").jqGrid('filterToolbar', { searchOperators: true });
$("#TableDataGrid").jqGrid('navGrid', '#DivPager', { add: false, edit: false, del: false, cancel: true, save: true, addtext: "Add", edittext: "Edit", deltext: "Delete", searchtext: "Search", refreshtext: "Refresh" },
$("#TableDataGrid").setGridParam({
onPaging: function (pgButton) {
var pageNumber = $("#TableDataGrid").getGridParam("page");
var lastPage = $("#TableDataGrid").getGridParam("lastpage");
alert(pageNumber + "" + lastPage);
//...
}
});
// var requestedPage = $("#grid").getGridParam("page");
// var lastPage = $("#grid").getGridParam("lastpage");
</script>
Here is json response
response = Convert.ToString(TfnUserView(groupName,isAdminCheck,isActiveCheck));
我正在调用WCF服务,这里是代码
public string TfnUserView(string groupName, string isAdminCheck)
{
using (TFNEntities db = new TFNEntities())
{
var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
string[] groupNames = groupName.Split(',');
string jsonData = "";
var query = from st in db.TFN_Campaigns
join tac in db.TFN_Records on st.TFN equals tac.TFN
join rou in db.TFN_ROUTING_REFERENCE_VIEW on st.TFN equals rou.TOLL_FREE_NO
where st.Status == false && tac.IsUnable == false
select new
{
st.TFN,st.Language,st.TeamName,st.CreatedOn,st.Status,tac.IsUnable,rou.ROUTE_TYPE ,
rou.ROUTE_DESCRIPTION
};
if (isAdminCheck == "True" || isAdminCheck == "true")
{
jsonData = serializer.Serialize(query.ToList().OrderBy(item => item.ROUTE_DESCRIPTION).Take(200254));
}
else
{
jsonData = serializer.Serialize(query.Where(item => groupNames.Contains(item.TeamName)).OrderBy(i=>i.ROUTE_DESCRIPTION).Take(25000));
}
return jsonData;
}
}
首先,这个链接:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:pager将帮助您在Jqgrid中配置分页。
然后可能你可以传递两个参数到你的WCF服务,页和rowNum。然后在linq中使用skip函数和take函数,如下所示。
jsonData = serializer.Serialize(query.ToList())。order (item => item. route_description)。
相关文章:
- asp.net MVC Ajax 发送两个参数
- ASP.NET - 在视图中访问 ViewBag
- 根据 ASP.NET 中的下拉选择显示特定列表
- 在 Asp.Net 中在服务器端创建标签
- 使用 Google OAuth 2 和 ASP.Net MVC 发送/接收电子邮件
- 将两个 dd/mm/yyy 字符串数组合并为一个,同时按 C# asp.net 顺序排列日期
- 记录每个用户登录/注销 ASP.Net 成员资格
- CSVHelper with ASP.NET MVC 3
- 将现有用户从 MVC 4 SimpleMembership 迁移到 MVC 5 ASP.NET Identity
- ASP.NET MVC5 无效的模型状态:如何将外键传递到下拉列表并将其传递回 HTTPPost
- ASP.Net 范围验证器日期停止正常工作
- 如何在工作进程 asp.net 的所有实例之间共享变量
- 如何使用 LINQ 和 asp.net 中的多视图控件每次从数据库获取单行
- ASP.NET IE中的闪烁
- 如何在 C# asp.net 中的另一个页面中更改站点地图中 URL 的默认重定向页面
- ASP.NET 跨应用程序使缓存失效的最干净方法
- 在 MVC 5 ASP.NET 将映像添加到数据库
- ASP.NET 如何将通知推送到客户端(与 Gmail 相同)
- asp.net Web API 405 方法不允许、发布、自定义操作
- ASP.NET MVC 会话为空.未设置会话变量