简体   繁体   中英

How to set Row data using rowid and column name in jQgrid

I've added a custom icon using below code in jqgrid Actions column. When the cutom icon is clicked, a pop up is opened with Textarea, Save and Close buttons. When I click Save button I wanted to save the text entered in textarea to a hidden field column in jQgrid. I tried 'setRowData' and 'setCell' properties but nothing works. Am I missing something here?

afterInsertRow: function (rowid, rowdata, rowelem) {
                $(this).triggerHandler("afterInsertRow.jqGrid", [rowid, rowdata, rowelem]);
                //...//
                //Start: Code for Notes Icon in Actions column
                var iCol = getColumnIndexByName(grid, 'actions');
                $(this).find(">tbody>tr#" + rowid + ">td:nth-child(" + (iCol + 1) + ")")
                        .each(function () {
                            $("<div>", {
                                title: "Custom",
                                mouseover: function () {
                                    $(this).addClass('ui-state-hover');
                                },
                                mouseout: function () {
                                    $(this).removeClass('ui-state-hover');
                                },
                                click: function (eve) {
                                    $("#change_dialog").dialog({
                                        buttons: {
                                            'Save': function () {
                                                var selRow = $(eve.target).closest("tr.jqgrow").attr("id");

                                                var txtNotes = $("#mytext").val();
                                                $("#gridJQ").setRowData(selRow, { 'notesHidden': txtNotes });

                                                $("#gridJQ").jqGrid('setCell', selRow, 'notesHidden', txtNotes);
                                                $("#gridJQ").jqGrid('setRowData', selRow, 'notesHidden', txtNotes);
                                                $(this).dialog("close");
                                            },
                                            'Close':function() {
                                                $(this).dialog("close");
                                            }
                                        }
                                    });

                                    return false;
                                }
                            }
                            ).css({ "margin-right": "5px", float: "left", cursor: "pointer" })
                                .addClass("ui-pg-div ui-inline-custom")
                                .append('<span class="ui-icon ui-icon-document"></span>')
                                .prependTo($(this).children("div"));
                        });

Instead of using this code to get the row

var selRow = $(eve.target).closest("tr.jqgrow").attr("id");

Try something a more direct such as

var selRow = $("#gridJQ").jqGrid('getGridParam', 'selrow');

Or even just var selRow = rowid .

Does that help at all?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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