如何在表单编辑中更改id列的值 [英] How to change value of id column in form editing

查看:153
本文介绍了如何在表单编辑中更改id列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用表单编辑来更改id列的值的方法.

I'm looking for a way to change the value of id column using form editing.

我在下面尝试了代码:选中行,在表单编辑按钮中单击并更改了anda和id. 按下后,提交按钮ID列的值不会在网格中更改.如何也更改id列的值?

I tried code below: selected row, clicked in form edit button and changed anda and id. After pression submit button id column value is not changed in grid. How to change id column vaue also ?

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.11.4/themes/redmond/jquery-ui.css"/>
    <link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/free-jqgrid/4.8.0/css/ui.jqgrid.css"/>
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
    <script type="text/javascript" src="http://cdn.jsdelivr.net/free-jqgrid/4.8.0/js/i18n/grid.locale-en.js"></script>
    <script type="text/javascript">
        $.jgrid = $.jgrid || {};
        $.jgrid.no_legacy_api = true;
        $.jgrid.useJSON = true;
    </script>
<script src="http://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>
    <script type="text/javascript">
        $(function () {
            "use strict";
            var mydata = [ { name: 'name', id:'id'}
                ],
                $grid = $("#list");

            $grid.jqGrid({
                datatype: "local",
                data: mydata,
                colNames: ["Client", "Id"],
                colModel: [
                    { name: "name",  editable: true },
                    { name: "id", editable: true }
                ],
                iconSet: "fontAwesome",
                pager: "#pager",
                gridview: true,
                autoencode: true,
                ignoreCase: true,
                onSelectRow: function (rowid) {
                    var $self = $(this),
                        savedRow = $self.jqGrid("getGridParam", "savedRow");
                    if (savedRow.length > 0) {
                        $self.jqGrid("restoreRow", savedRow[0].id);
                    }
                    $self.jqGrid("editRow", rowid, {
                        keys: true
                    });
                }
            })

.jqGrid('navGrid', {}, {},
{
//           afterSubmit: function (response, postdata) {
//postdata.id='100';
//               return [true, '']; //, '100'];
// }
})
;

        });
    //]]>
    </script>
</head>
<body>
    <table id="list"><tr><td></td></tr></table>
    <div id="pager"></div>
</body>
</html>

推荐答案

我无法对此进行测试,但我认为

I can't test this, but I think that the usage of

afterSubmit: function (response, postdata) {
    postdata.id='100';
    return [true, '', '100'];
}

应该工作.我认为您可以用这种方式修改任何甚至是不可编辑的列,但是仅在添加新行的情况下.

should work. I think that you can modify any even non-editable column in the way, but only in case of adding new row.

唯一的例外可能是id列,因为(或

The only exception could be the id column because of the line (or the line of jqGrid 4.7).

为确保没有我的情况,我修改了免费jqGrid的代码.您应该尝试使用免费的jqGrid的最新资源

To be sure that one don't have the case I modified the code of free jqGrid once more. You should try with the latest sources of free jqGrid

这篇关于如何在表单编辑中更改id列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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