JQGrid中的真正滚动数据不适用于MVC 3 [英] True scrolling data in JQGrid not working with MVC 3
问题描述
有人可以帮我解决这个问题吗?
我有一个jqgrid(4.4.0),我想实现真正的滚动.问题在于它仅加载一次数据行,这意味着仅第一页.因此,当我滚动时,它不会获取其他页面.我已经检查了此链接 仍然不起作用.
这是jqgrid:
Can someone help me with this issue?
I have a jqgrid(4.4.0) and I want to implement true scrolling. The problem is that it only loads datarows once, meaning the first page only. So when I scroll, it doesn''t fetch the other pages. I have checked this link and still not working.
Here is the jqgrid:
jQuery("#deptProjectsGrid").jqGrid({
url: '@Url.Action("GetUserProjects", "TimesheetByWeek")',
datatype: 'json',
mtype: 'GET',
colNames: ['Projekt', 'Oprettet af'],
colModel: [
{ name: 'project', index: 'project', sortable: true, align: 'left' },
{ name: 'creator', index: 'creator', align: 'left' }
],
height: 300,
width: 250,
altRows: true,
pager: '#pager1',
scroll: 1,
rowNum: 15,
rownumbers: true,
viewrecords: true,
sortname: 'project',
sortorder: 'desc',
gridview: true,
caption: "Projekter",
onSelectRow: function (ids) {
if (ids == null) {
ids = 0;
if ($taskgrid.jqGrid('getGridParam', 'records') > 0) {
$taskgrid.jqGrid('setGridParam', { url: '@Url.Action("GetProjectTasks", "TimesheetByWeek")/' + ids });
$taskgrid.jqGrid('setCaption', "No Tasks " + ids).trigger('reloadGrid');
}
} else {
var data = $("#deptProjectsGrid").getRowData(ids);
$taskgrid.jqGrid('setGridParam', { url: '@Url.Action("GetProjectTasks", "TimesheetByWeek")/' + ids });
$taskgrid.jqGrid('setCaption', "Tasks for " + data.project).trigger('reloadGrid');
}
}
});
控制器动作如下所示:
The controller action looks like this:
public JsonResult GetUserProjects(int page, int rows, string search, string sidx, string sord)
{
try
{
using (DanishEntities db = new DanishEntities())
{
int totalRecords = 0;
var allProjectEntities = _projectRepository.GetProjectsPaged(page, rows, out totalRecords, db);
var projects = Mapper.Map<List<Project>, List<ProjectModel>>(allProjectEntities);
var totalPages = (int)Math.Ceiling(totalRecords / (float)rows);
var jsonData = new
{
total = rows,
page = page++,
records = totalRecords,
rows = (
from p in projects
select new
{
id = p.ID,
cell = new object[] { p.Name, "john doe" }
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}
catch (Exception)
{
throw;
}
}
查询是:
and the query is:
public List<Project> GetProjectsPaged(int page, int rows, out int totalCount, DanishEntities dbContext)
{
List<Project> pagedProjectEntities = new List<Project>();
try
{
totalCount = dbContext.Projects.Count();
pagedProjectEntities = dbContext.Projects
.OrderBy(p => p.ID)
.Skip((page-1) * rows)
.Take(rows)
.ToList();
}
catch (Exception)
{
throw;
}
return pagedProjectEntities;
}
我一生都花了4个小时试图解决这个问题,但我根本看不出问题所在.我什至在控制器操作中设置了"total = totalPages",但没有任何反应.请帮忙!!
关于jqGrid的另一个快速问题:如何禁用jqGrid中的"rowNum",以便网格显示数据集中查询返回的所有可用行?
I have wasted 4 hours of my life trying to figure this out and I just can''t see the problem. I have even set "total = totalPages" in the controller action but nothing is working. Help please!!
Just another quick question on jqGrid: How do I disable "rowNum" in a jqGrid so that the grid shows all available rows returned by the query in the data set?
推荐答案
taskgrid.jqGrid(' getGridParam',' span> 记录')> 0 ){
taskgrid.jqGrid('getGridParam', 'records') > 0) {
taskgrid.jqGrid(' setGridParam',{url:' @ Url.Action("GetProjectTasks" ,"TimesheetByWeek")/' + ids});
taskgrid.jqGrid('setGridParam', { url: '@Url.Action("GetProjectTasks", "TimesheetByWeek")/' + ids });
taskgrid.jqGrid(' setCaption'," + ids.trigger (' reloadGrid'); } } 其他 { var data =
taskgrid.jqGrid('setCaption', "No Tasks " + ids).trigger('reloadGrid'); } } else { var data =
这篇关于JQGrid中的真正滚动数据不适用于MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!