【发布时间】:2011-10-03 21:08:55
【问题描述】:
我显示一个 jqGrid 配方表,并为用户提供一个主从类型视图。当用户从网格中选择一个配方时,它会在网格下方的 div 中显示该配方的详细信息。然后,我在该 div 中提供了就地编辑功能。当用户保存编辑时,我会重新显示配方的详细信息。这一切都很好。现在,选定的网格行可能包含与更新后详细信息显示的数据不匹配的数据,因此我执行以下操作来更新网格:
$.ajax({
type: "GET",
data: "id=" recipeId,
url: '@Url.Action("GetGridDataForRecipe", "Recipe")',
dataType: "json",
success: function (result) {
var myGrid = $("#recipeGrid");
var selRowId = myGrid.jqGrid('getGridParam', 'selrow');
myGrid.jqGrid('setRowData', selRowId, result);
}
});
我的控制器操作如下所示:
public JsonResult GetGridDataForRecipe(int id)
{
// ...
var recipeData = context.recipes.Where(m => m.RecipeId == id).Select(row => new
{
RecipeId = row.RecipeId,
RecipeName = row.RecipeName,
RecipeDate = row.RecipeDate,
}).First();
return Json(recipeData, JsonRequestBehavior.AllowGet);
}
因此,更新工作几乎完美,但 RecipeDate 条目最终显示如下:
/Date(1317182400000)/
而不是格式化的日期:
10/03/2011
当我返回网格行时,我在colModel 中指定:
{ name: 'RecipeDate', index: 'RecipeDate', width: 120, align: 'left', sorttype: 'date',
formatter: 'date', formatoptions: { newformat: 'm/d/Y'},
...
我在显示网格时指定的colModel 与我稍后要更新的数据之间存在脱节。我需要重新指定这些信息吗?我该怎么做?
【问题讨论】:
标签: javascript jquery asp.net-mvc-3 jqgrid