简体   繁体   English

添加新行后,jqGrid内联编辑不起作用

[英]jqGrid inline editing not working after adding new row

I'm currently using free-jqGrid version 4.14.1 (using cdn hyperlink). 我当前正在使用free-jqGrid版本4.14.1(使用CDN超链接)。 I would like to let the users add a new row with their input values, and edit the row if they want to make any change by clicking the row. 我想让用户使用其输入值添加一个新行,如果他们想通过单击该行进行任何更改,请对其进行编辑。 For adding new row, I created an adding button (not using jqGrid pager). 为了添加新行,我创建了一个添加按钮(不使用jqGrid分页器)。

I'm now facing two different issues: 我现在面临两个不同的问题:

1) I refered this demo for inline editting. 1)我参考了此演示进行内联编辑。 According to this demo code, I need to use the line 根据此演示代码,我需要使用该行

grid.jqGrid('restoreRow', lastSelection);

However, with this line, everytime I am adding new row, the previous row is deleted and only newly added row is displayed. 但是,在这一行中,每次我添加新行时,都会删除前一行,并且仅显示新添加的行。 Please check this fiddle . 请检查这个小提琴

2) Due to 1), I commented out that line(I don't think I supposed to do that for proper functioning), and tried to run. 2)由于1),我注释掉了该行(我认为我不应该为了正常运行而这样做),并尝试运行。 The previously added rows remain after adding new row, but all rows displayed is showing in textbox like this (fiddle) : 在添加新行之后,先前添加的行仍然保留,但是显示的所有行都显示在文本框中,如下所示(小提琴)

在此处输入图片说明 What I would like to have is only after user clicks the row to modify, it changes to the textboxes like the guriddo demo. 我只想在用户单击要修改的行后才将其更改为类似于guriddo演示的文本框。

I have not found any post related to this issues. 我尚未找到与此问题相关的任何帖子。 Is there anyone please help me?? 有没有人请帮助我?

============================================ ===========================================

Add: 加:

I started with some base table value just for verification. 我从一些基本表值开始,仅用于验证。 The base data rows were functioning as I wanted (click the row for modification), but the new rows were not. 基本数据行正在按我的要求运行(单击要修改的行),但是新行却没有。 It seems like new rows are not selected and not focused when I click, and not exiting the edit mode after hitting enter key.. 当我单击时,似乎未选择新行且未将焦点对准,并且在按Enter键后未退出编辑模式。

在此处输入图片说明

============================================ ===========================================

============================================ ===========================================

The below is the code of grid just for reference: 下面是网格代码,仅供参考:

$(document).ready(function () {

        Load_Bin();

        $('#Bin-QtyBin').focus();
        $('#btnEnter-Bin').click(function () {

                var valNumBin = $('#Bin-numBin').val();
                //if bins are dropbox: select enabled one

                var valQtyBin = $('#Bin-QtyBin').val();


                var paramRow = {
                    rowId: "new_row",
                    initdata: {
                        numBin: valNumBin,
                        QtyPutAway: valQtyBin
                    },
                    position: "first" //"last"
                }

                $("#tbBin").jqGrid('addRow', paramRow);
                $('#Bin-numBin').val('');
                $('#Bin-QtyBin').val('');

        });
});
    var lastSelection;

    function Load_Bin() {
        var tbBinArea = $('#tbBin');
        tbBinArea.jqGrid({
            datatype: "local",
            colModel: [
                { label: 'Bin', name: 'numBin', sorttype: 'text', searchoptions: { clearSearch: true }, width: 310, editable: true },
                { label: 'Put Away Qty.', name: 'QtyPutAway', sorttype: 'number', searchoptions: { clearSearch: true }, width: 310, editable: true }],
            rowNum: 10,
            rowList: [10, 15, 30, "10000:All"],
            prmNames: {
                page: 'defaultPageNumber',
                rows: 'rowsPerPage'
            },
            //forceClientSorting: true,
            rownumbers: true,
            //autowidth: true,
            viewrecords: true,
            loadonce: true,
            multiselect: false,
            multiPageSelection: false,
            iconSet: "fontAwesome",
            pager: true,
            height: 250,
            onSelectRow: editRow, 
            searching: {
                searchOperators: true,
                defaultSearch: 'cn',
                closeOnEscape: true,
                searchOnEnter: false,
                multipleSearch: true
            }
        });

    }


    function editRow(id) {

        if (id && id !== lastSelection) {
            var grid = $("#tbBin");
            grid.jqGrid('restoreRow', lastSelection);
            grid.jqGrid('editRow', id, { keys: true });
            lastSelection = id;
        }
    };

(ps thanks to the owner of this fiddle since I was struggling to move the code to fiddle, and sorry for not addressing him/her since I lost the original answer link for that fiddle... ) (ps感谢此小提琴的所有者,因为我一直在努力将代码移到小提琴,并且由于我丢失了该小提琴的原始答案链接而未能与他/她联系,所以感到抱歉...)

I ended up just reload the whole grid after adding new row. 我最终只是在添加新行后重新加载整个网格。 It works fine, except that newly added line does not turn to edit mode since it doesn't detect whether user clicks it or not since it is already highlighted when it was created.. 它可以正常工作,但新添加的行不会变为编辑模式,因为它不会检测用户是否单击它,因为它在创建时已被突出显示。

After creating new row, just added this code: 创建新行后,只需添加以下代码:

            var reloaddata = $('#tbBin').jqGrid("getGridParam", "data");

            $('#tbBin')
                .jqGrid('setGridParam',
                {
                    datatype: 'local',
                    data: reloaddata
                })
                .trigger("reloadGrid");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM