更新jqGrid行时格式丢失
Formatting lost when updating jqGrid row
显示食谱的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
与我稍后更新的数据之间存在脱节。我需要重新指定这些信息吗?我怎么做呢?
我需要重新指定这个信息吗?
是的。
我该怎么做?
你可以在从控制器动作返回的匿名对象中执行此格式化:
var recipeData = context.recipes.Where(m => m.RecipeId == id).Select(row => new
{
RecipeId = row.RecipeId,
RecipeName = row.RecipeName,
RecipeDate = row.RecipeDate.ToString("MM/dd/yyyy"),
}).First();
在GitHub上找到答案。
添加.jgrid.formatter.date美元。reformatAfterEdit = true;在我调用setRowData之前,现在似乎是一个很好的工作。
我添加了这段代码,我的日期现在显示为我期望的格式。
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- 货币代码为欧元-金额的格式不应包含小数
- Json数据包含日期和时间格式
- Javascript日期格式类似于ISO,但本地
- jqGrid树网格问题
- 更改angularjs中的日期-时间格式
- 将日期时间从json转换为可读格式
- NodeJS日期格式不起作用
- 我能得到正确的格式吗
- Intercept the cellSubmit jqGrid
- PHP:显示sqlite数据库中的html格式数据,使用tinymce保存
- 使用正则表达式将输入格式设置为单字符逗号、单字符逗号等
- 将日期和时间转换为UTC格式的日期-Javascript
- Jqgrid 24小时格式的日期列
- JQGrid - 日期过滤器不适用于日期格式(日期(1453636335000))
- jqgrid日期时间格式
- 如果未返回任何值,则保持货币格式的JQgrid单元格为空,不带默认值
- 更新jqGrid行时格式丢失
- Jqgrid条件格式
- 使用jqGrid的自定义JSON格式