JQGrid Formatter 在线编辑后生成不正确的代码
JQGrid Formatter generating incorrect code after in-line edit
我的 "Formatter" 在对该行执行内联编辑后生成了不正确的代码。在我保存内联编辑并尝试单击该行的 "Edit: ##" 后,我收到 404.
1) 当页面首次加载(或重新加载)时,您可以看到 link 的正确 URL 和 html 代码:
2) 现在我执行内联编辑并单击“保存 JqGrid 操作”图标:
3) 错误--> EDIT link 现在似乎包含两次相同的 HTML 代码:
我的网格的 colModel:
colModel: [
{"width":"50","fixed":true,"search":true,"editable":false,"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge","nu","nn"]},"sortable":true,"formatter":fullEditTemplate,"name":"id","label":"ID"},
{"formatter":"actions","formatoptions":{"afterSave":easygrid.afterSave('templateGrid_table'),"onError":easygrid.onError('templateGrid_table'),"keys":true,"delbutton":false},"searchoptions":{"clearSearch":false},"search":false,"name":"actions","width":"50","sortable":false,"resizable":false,"label":"Edit","fixed":true,"editable":false},
{"formatter":templateDuplicateFormat,"label":"Duplicate","searchoptions":{"clearSearch":false},"search":false,"editable":false,"name":"version","sortable":true,"width":"70"},
{"searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew","nu","nn"]},"editable":true,"sortable":true,"width":"250","name":"templateName","search":true,"label":"Template Name"}
],
这是完整的EditTemplate函数:
function fullEditTemplate(cellvalue, options, rowObject) {
return "<a href='${g.createLink(controller: "template", action: "edit")}/" + cellvalue + "'> Edit: " + options.rowId + "</a> ";
}
谢谢!!
这是因为你没有指定fullEditTemplate对应的unformmater。只要网格是只读的,格式化程序就可以在没有格式化程序的情况下很好地工作,但是如果我们需要内联或编辑意外的行为,就像你发生的那样。
来自 Documentation 以下是您应该如何修复它
首先将格式化程序添加到 colModel
{"width":"50","fixed":true,"search":true,"editable":false,"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge","nu","nn"]},"sortable":true, "unformat":fullEditTemplateUnformat,"formatter":fullEditTemplate,"name":"id","label":"ID"},
您定义格式化程序函数如下。
function fullEditTemplateUnformat( cellvalue, options, cell){
var anchortext= $('a', cell).text();
var resultValue=anchortext.split(":"); // resultValue[0] is the Edit and resultValue[1] is what we are looking for
return resultValue[1].trim();
}
我的 "Formatter" 在对该行执行内联编辑后生成了不正确的代码。在我保存内联编辑并尝试单击该行的 "Edit: ##" 后,我收到 404.
1) 当页面首次加载(或重新加载)时,您可以看到 link 的正确 URL 和 html 代码:
2) 现在我执行内联编辑并单击“保存 JqGrid 操作”图标:
3) 错误--> EDIT link 现在似乎包含两次相同的 HTML 代码:
我的网格的 colModel:
colModel: [
{"width":"50","fixed":true,"search":true,"editable":false,"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge","nu","nn"]},"sortable":true,"formatter":fullEditTemplate,"name":"id","label":"ID"},
{"formatter":"actions","formatoptions":{"afterSave":easygrid.afterSave('templateGrid_table'),"onError":easygrid.onError('templateGrid_table'),"keys":true,"delbutton":false},"searchoptions":{"clearSearch":false},"search":false,"name":"actions","width":"50","sortable":false,"resizable":false,"label":"Edit","fixed":true,"editable":false},
{"formatter":templateDuplicateFormat,"label":"Duplicate","searchoptions":{"clearSearch":false},"search":false,"editable":false,"name":"version","sortable":true,"width":"70"},
{"searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew","nu","nn"]},"editable":true,"sortable":true,"width":"250","name":"templateName","search":true,"label":"Template Name"}
],
这是完整的EditTemplate函数:
function fullEditTemplate(cellvalue, options, rowObject) {
return "<a href='${g.createLink(controller: "template", action: "edit")}/" + cellvalue + "'> Edit: " + options.rowId + "</a> ";
}
谢谢!!
这是因为你没有指定fullEditTemplate对应的unformmater。只要网格是只读的,格式化程序就可以在没有格式化程序的情况下很好地工作,但是如果我们需要内联或编辑意外的行为,就像你发生的那样。
来自 Documentation 以下是您应该如何修复它
首先将格式化程序添加到 colModel
{"width":"50","fixed":true,"search":true,"editable":false,"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge","nu","nn"]},"sortable":true, "unformat":fullEditTemplateUnformat,"formatter":fullEditTemplate,"name":"id","label":"ID"},
您定义格式化程序函数如下。
function fullEditTemplateUnformat( cellvalue, options, cell){
var anchortext= $('a', cell).text();
var resultValue=anchortext.split(":"); // resultValue[0] is the Edit and resultValue[1] is what we are looking for
return resultValue[1].trim();
}