jqGrid内联编辑:如果帖子返回错误,如何再次保存 [英] jqGrid inline edit: how to save again if post returns error

查看:70
本文介绍了jqGrid内联编辑:如果帖子返回错误,如何再次保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQgrid行使用内联编辑模式进行编辑. 按Enter使用http POST将数据发送到服务器. 如果存在某些错误,POST方法将返回状态400错误的请求.下面的代码中的errorofunc在此显示错误 案件. 用户更正行中的数据,然后再次按Enter.

jQgrid row is edited using inline editing mode. Pressing Enter sends data to server using http POST . POST method returns status 400 Bad reguest if there was some error. errorofunc in code below show error in this case. User corrects data in row and presses enter again.

按Enter键将被忽略,没有任何反应.如果返回404错误,则好像Enter键未绑定. 编辑的行中的更改丢失,无法保存.

Pressing enter is ignored, nothing happens. It looks like Enter key is unbound if 404 error is returned. Changes in edited row are lost, they cannot saved.

我试图设置为errorfunc

I tried to set in errorfunc

restoreAfterError = false; grid.restoreAfterErorr = false;

restoreAfterError = false; grid.restoreAfterErorr = false;

但是错误后行仍然无法再次保存.

but row still cannot saved again after error.

返回400错误后如何允许保存正确的行数据?

How to allow to save correct row data after 400 error is returned ?

<script type="text/javascript">
var lastSelectedRow;
$(function () {
            var grid = $("#grid");
            grid.jqGrid({
                url: '/Grid/GetData',
                datatype: "json",
                mtype: 'POST',
                scroll: 1,
                multiselect: true,
                multiboxonly: true,
                scrollingRows : true,
                autoencode: true,
                colModel: [
        { name: 'Source', fixed: true, editable: true, width: 30 },
        { name: 'Est', fixed: true, editable: true, width: 271 },
        { name: 'Istopic', fixed: true, editable: true, width: 57 },
        {name: 'Critical', fixed: true, editable: true, width: 50}
    ],

                gridview: true,
                pager: '#pager',
                sortname: 'est',
                viewrecords: true,
                rowNum: 30,
                sortorder: "asc",
                editurl: '/Grid/Edit'
            });

            $("#grid").jqGrid('bindKeys', {
                onEnter: function(rowid) {
                    doeditRow(rowid);
                }
            }  );

        });

        function doeditRow(rowID) {
            var grid2 = $("#grid");
            if (rowID && rowID !== lastSelectedRow) {
                grid2.jqGrid('restoreRow', lastSelectedRow);
                lastSelectedRow = rowID;
            }
            invokeEditRow();
        }

        function errorfunc(rowID, response) {
            // todo: why this does not allow Enter key to continue ase after error:
            restoreAfterError = false;
            $("#grid").restoreAfterErorr = false;
            alert(response.responseText);
            lastSelectedRow = rowID;
            invokeEditRow();
            return true;
        }


        function invokeEditRow() {
             $("#grid").jqGrid('editRow', lastSelectedRow ,true,null, null, null, {},
                 null,
                 errorfunc
             );
        }
    </script>

<div id="grid1container" style="width: 100%;">
    <table id="grid">
    </table>
    <div id="pager">
    </div>
</div>

更新:errrofunc调用editrow其中 根据 https://github.com/tonytomov/jqGrid/blob/master /js/grid.inlinedit.js 应该再次设置回车键保存. 由于未知原因,这不会 发生.

UPDATE: errrofunc calls editrow which according to https://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js should set enter key again to save. For unknown reason this does not occur.

更新:在errorfunc网格中.更改为

UPDATE: in errorfunc grid. is changed to

        $("#grid").restoreAfterErorr = false;

根据Oleg评论

推荐答案

您可以在errorfunc实现(grid.restoreAfterErorr)内使用变量grid. gridundefined,并且该行中有异常.

You use variable grid inside of errorfunc implementation (grid.restoreAfterErorr). The grid is undefined and you have exception in the line.

已更新:您应该将alert(response.responseText);替换为

$.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+
    response.responseText +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});

以查看与标准情况下相同的样式对话框.内联编辑中的errorfunc负责显示错误消息本身.

to see the same styled dialog box as in the standard case. The errorfunc from the inline editing is responsible to display the error message itself.

这篇关于jqGrid内联编辑:如果帖子返回错误,如何再次保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆