我显示jqGrid食谱表并为用户提供主 - 细节类型视图。当用户从网格中选择配方时,它会在网格下方的div中显示该配方的详细信息。然后,我在该div内提供一个就地编辑功能。当用户保存编辑时,我会重新显示配方的详细信息。这一切运作良好。现在,选择的网格行可能有不匹配的内容的细节更新后显示的数据,所以我做这样的事情来更新网:更新jqGrid行时格式丢失
$.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
,我以后更新的数据之间的脱节。我是否需要重新指定这些信息?我怎么做?
感谢达林 - 现在,这比我想象的要简单得多。很棒。 – itsmatt
这个答案需要在服务器端复制格式化代码,这远远不够理想。我会继续寻找。 – DCShannon