Toolbar search local data, retain value in cell even after searching

拈花ヽ惹草 提交于 2019-12-06 16:48:01
Oleg

The origin of the problem seems to me in the using the behavior which you described like

... one column 'Transfer Qty.' which is by default editable.

You calls editRow for all rows of the grid. So you set all the rows of the grid in editing state. It's not recommended way because it creates more problems.

The problem is the following. If you starts inline editing then jqGrid saves the original values from all editing rows inside of internal savedRow parameter which is array of original values of all editing rows. During inline editing the user can make some changes in any from the editable fields, but the user can cancel the changes by pressing Esc key. In other words jqGrid have to hold both old values and the current (not yet saved) modified values. If the user clicks on the column header then jqGrid sort by the column by default. Sorting means re-filling the current page of the grid. It's unclear whether the current editable rows should be saved or discarded. So the sorting are typically prohibited during inline editing. The same problem exist with searching.

If you want to allow searching during inline editing and if you need to save the data then you have to call saveRow in the loop inside of beforeSearch callback of filterToolbar. Exactly like you explicitly calls editRow for all rows inside of loadComplete you have to call saveRow for all rows inside of beforeSearch before trigger of reloadGrid.

One more remark to your code. It seems to me that the last row of the grid have special meaning - it contains the footer information. You set ireg-jqgrid-lastrow class on the row inside of gridComplete. The row will be not editable. Such scenario seems to me could be implemented in another way in jqGrid. You can add footerrow: true option in the grid. It add separate div below of the main grid, but all looks very close to the picture which you included. The main difference exist in separation of the main data from the footer. You can use footerData method to will the data in the footer or you can use userDataOnFooter: true option. jqGrid will the footer automatically with the data from userdata part of the data returned from the server. See the old answer and this one or this one for the corresponding demos and implementation details.

SOLUTION:- I have implemented loadonce: true

oGrid.jqGrid('filterToolbar', { stringResult: true, defaultSearch: 'cn', //groupOp: 'OR',
    beforeSearch: function () {

        var oRules = new Array();
        var postdata = $('#tbLots').jqGrid('getGridParam', 'postData'), 
            oCustFilter = $.parseJSON(postdata.filters), colName, searchStr, operator, groupOperator = '';
        for (var i = 0; i < oCustFilter.rules.length; i++) {
            groupOperator = oCustFilter.groupOp;
            searchStr = oCustFilter.rules[i].data;
            colName = oCustFilter.rules[i].field;
            operator = oCustFilter.rules[i].op;

            oRules.push({ field: colName, op: operator, data: searchStr });
        }

        var oFilter = { groupOp: groupOperator, rules: oRules };
        $.extend(postdata, { filters: JSON.stringify(oFilter) });
        $('#tbLots').jqGrid('setGridParam', { search: true, postData: postdata });
        //$('#tbLots').trigger("reloadGrid", [{ page: 1}]);
    }

    /*here is the code, what you taught me to do*/
    var l_oIds = oGrid.jqGrid('getDataIDs'), i;
    for (i = 0; i < l_oIds.length; i++) {
        oGrid.jqGrid('saveRow', l_oIds[i], false, 'clientArray');
    }

    //reloading grid after saverow
    $('#tbLots').trigger("reloadGrid", [{ page: 1}]);

    return true;
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!