0

I'm using jqgrid 4.8.2. If a user clicks on a row, I want to save the previously selected row and display the current row in edit mode. I've used the code from previous answers but can't get this functionality to work. After some debugging and looking through the source code for jqgrid, it appears saveRow does not fire because the 'editable' attribute for the previous row is immediately set to 0. There is a clause in the jqgrid source code that looks for this attribute before saving the row:

editable = $(ind).attr("editable");
o.url = o.url || $t.p.editurl;
if (editable==="1") {....saveRow occurs...}

Any suggestion on how to work around this?

var editingRowId;
var myEditParam = {
keys: true,
     extraparam: {activityID: aID},
     oneditfunc: function (id) { editingRowId = id; },
     afterrestorefunc: function (id) { editingRowId = undefined; },
     aftersavefunc: function (id) { editingRowId = undefined; }
};
var myGrid =  jQuery("#spend_grid").jqGrid({
            url: parentGridURL,
            mtype: "POST",
            datatype: "json",
            postData:       {filters: myFilters},
            gridview:       false, //added for IE 
            altRows:        true,
            emptyrecords:   'NO PAYMENTS FOUND',
            editurl:        savePaymentURL,
            onSelectRow:    function (id) {
                                console.log('id=' + id + ' editingRowId =' +  editingRowId);
                                var $this = $(this);
                                if (editingRowId !== id) {
                                    if (editingRowId) {
                                        // save or restore currently editing row
                                        console.log('should be saving ' + editingRowId);
                                        $this.jqGrid('saveRow', editingRowId, myEditParam);
                                        console.log('done saving');
                                    }
                                    $this.jqGrid("editRow", id, myEditParam);
                                }
                            },
            search:         true,
            sortname:       lastSortName,
            sortorder:      lastSortOrder,
            page:           lastPage,
            pager:          jQuery('#report_pager'),
            rowNum:         lastRowNum,
            rowList:        [10,20,50,100],
            viewrecords:    true,
            clearSearch:    false,
            caption:        "Payments",
            sortable:       true,
            shrinkToFit:    false,
            excel:          true,
            autowidth:      true,
            height:         300,
            subGrid:        true, // set the subGrid property to true to show expand buttons for each row
            subGridRowExpanded: showChildGrid, // javascript function that will take care of showing the child grid
            colModel: [
                { label: 'Payment ID', 
                    name: 'PAYMENTID', 
                    index: 'p.paymentID', 
                    key: true, width: 75 
                },...// removed for brevity
               {name : 'actions', 
                    label: 'Actions',
                    index: 'formAction', 
                    formatter:'actions',
                    width: 75,
                    search:false,
                    formatoptions: {
                        keys: true,
                        editbutton: false,
                        delOptions: { url: savePaymentURL }
                    }
                }
            ]

        }).inlineNav('#report_pager',
            // the buttons to appear on the toolbar of the grid
            { 
                restoreAfterSelect: false, // *****SOLUTION******
                save:false,
                edit: false, 
                add: false, 
                cancel: false


        });
Community
  • 1
  • 1

1 Answers1

0

Found a solution to the issue. After examining the jqgrid source code I found that restoreAfterSelect: true is the default setting for the inlineNav. I added restoreAfterSelect: false and now the previous row saves.