简体   繁体   中英

Jqgrid custom formatter and edit mode

It appears that using a custom formatter makes the cell stuck in the edit mode and previously edited row never gets restored.

JS, grid defined here

 $(priceListGrid).jqGrid({
            datatype: 'local',          
            url: common.getServerPath() + 'controller/action',
            mtype: 'POST',
            jsonReader: common.jqgrid.jsonReader('Id'),
            colModel: [
            { name: 'MethodCode', label: 'MethodCode', index: 'MethodCode', hidden: true },
            { name: 'PriceCode', label: 'Price Code', index: 'PriceCode', width: '20px' },
            { name: 'Description', label: 'Description', index: 'Description', width: '34px' },
            { name: 'RoundTo', label: 'RoundTo', index: 'RoundTo', width: '10px' },
            {
                name: 'MinPrice',
                label: 'Min Pr',
                index: 'MinPrice',
                width: '15px',
                align: 'right',               
                formatter: customCurFormatter,
                editable: true,
                editrules: {
                    number: true,
                    minValue: 0,
                    custom: true,
                    custom_func: validateMinPrice
                }
            }
                ],
                caption: 'Price Entity List',
                hidegrid: false,
                ignoreCase: true,
                viewrecords: true,
                recordtext: '{2} Entity(ies).',
                autowidth: true,
                shrinkToFit: true,
                scroll: 1,
                sortname: 'PriceCode',
                sortorder: 'asc',
                rowNum: 500,
                altRows: true,
                altclass: 'gridAltRowClass',
                pager: '#pagerEntityPriceListDetails',
                onCellSelect: priceItemSelect,
                onSelectRow: onSelectPrice,
                afterSubmitCell: function (rowid) {
                    this.setRowData(rowid, info.Data, null);
                },
                loadComplete: priceListEntityLoadComplete,
                loadError: function (xhr, status, error) {
                    common.ajax.alsJsonError(xhr, status, error);
                    //stopDataLoading();
                }//,
                //loadBeforeSend: function () { isDataLoadingCount++; },
                //beforeSelectRow: function () { return !getIsDataLoading(); }
            })

this is the formatter

var customCurFormatter = function (cellvalue, options, rowObject) {       
    return cellvalue.toFixed(rowObject.RoundTo);
}

When it's used, as opposed to formatter:currency , the cell is stuck in edit mode when going over to the next line.

Any ideas would be appreciated.

The current code of the custom formatter is wrong, because toFixed method could be applied to Number and not to string. The cellvalue has String type at least during editing. Minimal changes of the code of the formatter should be

var customCurFormatter = function (cellvalue, options, rowObject) {       
    return Number(cellvalue).toFixed(rowObject.RoundTo);
}

You code has many other problems. For example, it's strictly recommended to define always unformat callback together with formatter .

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