JQGrid Formatter在内联编辑后生成错误的代码

时间:2016-06-16 16:32:03

标签: javascript jquery jqgrid grid

我的“Formatter”在对该行执行内联编辑后生成了错误的代码。保存我的内联编辑并尝试单击该行的“编辑:##”后,我得到了404。

1)当页面首次加载(或重新加载)时,您可以看到正确的URL&该链接的HTML代码是: correct URL & html code for the link are there

2)现在我执行内联编辑并单击SAVE JqGrid Actions图标: perform an in-line edit and click on the SAVE

3)错误 - > EDIT链接现在似乎包含两次相同的HTML代码: HTML code is duplicated

我的网格的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"}


],

这是fullEditTemplate函数:

function fullEditTemplate(cellvalue, options, rowObject) {
        return "<a href='${g.createLink(controller: "template", action: "edit")}/" + cellvalue + "'> Edit: " + options.rowId + "</a> ";
}

谢谢!

1 个答案:

答案 0 :(得分:1)

原因是你没有指定与fullEditTemplate对应的unformmater。只要网格是只读的,但是如果我们需要内联或形成编辑意外行为(如您所发生的那样),格式化程序就可以很好地处理非格式化程序。

Documentation这里是你应该如何解决它

首先将unformatter添加到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"},

您可以按如下方式定义unformatter函数。

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();
}