【发布时间】:2012-02-13 10:17:48
【问题描述】:
您好,我正在使用 jqgrid 在 .net MVC 3.0 C# 应用程序中加载一些数据。
有一个材质网格需要在大约 6 个不同的地方加载。他们都是一样的。该网格列出了大约 8700 种商品的定价和详细信息。
我遇到的问题是“成本”和“价格”两列的计算是从数据库执行的。这两列使网格加载极其缓慢。
我们使用的材料测试清单最初有大约 730 个项目。第一次没有某种优化,网格需要大约 1 分 30 秒才能完全加载。更改后,这下降到大约 4 秒,这是可以接受的。
我们现在正在处理将用于材料的真实列表,该列表包含 8500 多个项目。初始加载后,手表加载 8500 件商品大约需要 2 分钟。
这真的是不可接受的,所以我认为最好的解决方案是让搜索工具栏功能或外部搜索成为加载项目但仅加载搜索结果项目的功能。
所以我想看到的是,在初始页面加载后,网格是空的,只有在搜索完成后才会被填充,并且只显示搜索结果。
如果可能的话,最好使用搜索工具栏功能来做到这一点。这已经正常工作,但在初始长负载之后。
非常欢迎任何建议。我不是最初的程序员,只是想获取一些信息,所以如果可能的话,我不必为我的开发人员支付谷歌搜索费用。
感谢您的宝贵时间,如果需要当前代码的示例,请告诉我是否有帮助,或者如果我需要的话,您是否可以提供一些示例代码,
服务器端代码:
public ActionResult EstimateMaterialAddGridData(string sidx, string sord, int page, int rows)
{
IQueryable<Material> mats;
mats = Material.Find(x => x.OwnerId == UserAccount.GetOwnerId && x.isDeletedFromCatalog == false).AsQueryable();
int pageIndex = page - 1;
int pageSize = rows;
int totalRecords = mats.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (
from sub in mats
select new
{
i = sub.Id,
cell = new string[] {
sub.Id.ToString(),
sub.Id.ToString(),
sub.Id.ToString(),
sub.ProductCode,
sub.Description,
sub.Units,
sub.Categories,
sub.UnitCost.ToString(),
sub.Price.ToString()
}
}
).ToArray()
};
return Json(jsonData);
}
JS网格代码`jQuery(document).ready(function () { var grid = jQuery("#mgrid");
grid.jqGrid({
url: '/Material/EstimateMaterialAddGridData',
datatype: 'json',
mtype: 'POST',
colNames: ['Id', '','View/Edit', 'Product Code', 'Description', 'Units', 'Categories', 'Cost', 'Price'],
colModel: [
{ name: 'Id', index: 'Id', key: true, hidden: true, editrules: { edithidden: true} },
{ name: 'Add', index: 'Add', sortable: false, width: 50,search:false, resizable: false, editable: false, align: 'center', formatter: formatLink, classes: 'not-editable-cell' },
{ name: 'Open', index: 'Open', sortable: false, width: 90,search:false, resizable: false, editable: false, align: 'center', formatter: formatLinkNew, classes: 'not-editable-cell' },
{ name: 'ProductCode', index: 'ProductCode', sorttype: 'text',search:true, width: 100, resizable: false },
{ name: 'Description', index: 'Description', sorttype: 'text',search:true, width: 275, resizable: false },
{ name: 'Units', index: 'Units', sorttype: 'text', width: 75,search:true, resizable: false },
{ name: 'Categories', index: 'Categories', sorttype: 'text',search:true, width: 300, resizable: false, editable: false, },
{ name: 'UnitCost', index: 'UnitCost', sorttype: 'float', width: 75,search:true, align: 'right', resizable: false, editable: false, formatter: 'currency' },
{ name: 'Price', index: 'Price', sorttype: 'float', width: 75, search:true,align: 'right', resizable: false, editable: false, formatter: 'currency' },
],
pager: '#mpager',
height: '100%',
rowNum: 10,
rowList: [10, 20, 50, 100],
sortname: 'Id',
sortorder: 'desc',
sortable: true,
loadonce: true,
ignoreCase: true,
viewrecords: true,
caption: 'Material',
cellEdit: false,
hidegrid: false,
viewrecords: true,
});
grid.jqGrid('navGrid', '#mpager',
{ resize: false, add: false, del: false, search: true, refresh: true, edit: false, alerttext: 'Please select an material' }
).jqGrid('navButtonAdd', '#mpager',
{ title: "Create New Material Catalouge", buttonicon: "ui-icon-plus", onClickButton: newMaterial, position: "First", caption: "" });`
【问题讨论】:
-
能否包含目前使用 jqGrid 的代码?您能否提供有关“成本”和“价格”列的实施的更多信息。我不明白为什么你应该对列有任何问题。产生列值的 SELECT 是不是太慢了?
标签: c# javascript asp.net-mvc jqgrid