你好,我正在使用jqgrid加载一些.net MVC 3.0 C#应用程序中的数据。jqgrid工具栏搜索或外部搜索功能
有一个材料网格需要在大约6个不同的地方加载。他们都是一样的。网格列出了大约8700个项目的定价和细节。
我遇到的问题是两列“成本”和“价格”具有从数据库执行的计算。这两列使网格加载非常缓慢。
我们合作的材料测试列表最初有730个项目。第一次没有某种优化,电网需要大约1分30秒才能完全加载。变化之后,这降低到大约4秒,这是可以接受的。
我们现在正在处理将用于材料的真实列表,并且此列表包含8500个项目。在负载之后,它正在谈论2分钟,通过观看来装载8500个物品。
这真的不能接受,所以我认为最好的解决方案是让搜索工具栏功能或外部搜索加载项目,但只有搜索结果项目。
所以我想看到的是,在加载初始页面后,网格是空的,只有在搜索完成后才会填充,并且只显示搜索结果。
如果可能的话,最好能够使用搜索工具栏功能来做到这一点。这已经正常工作,但经过了长时间的负荷。
任何建议将非常欢迎。我不是原始程序员只是想获得一些信息,所以如果可能的话,我不必为我的开发支付谷歌搜索。
谢谢您的时间,如果需要在当前的代码示例,请让我知道它是否会帮助或如果你能提供一些示例代码,如果我需要的是可能的,
塞雷尔语端代码:
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网格code`jQuery(文件)。就绪(函数(){ VAR网格= 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是否太慢? – Oleg 2012-02-13 10:34:14