Can't hit save when no lines have been added

Developer
Apr 28, 2011 at 9:08 AM

There's a bug that raises an exception when a user tries to save without any changes;

Adding a check that gridRows has been assigned solves the problem;

function gridSaveRows(gridName, saveUrl, parameterName, callback) {
    var currGrid = $("#" + gridName);
    var gridRows = _gridNewRows[gridName];
    var rowsData = new Array();
    var i;

    if (gridRows != undefined) {
        for (i = 0; i < gridRows.length; i++) {
            jQuery("#" + gridName).jqGrid('saveRow', gridRows[i], null, "clientArray");
            rowsData.push(currGrid.getRowData(gridRows[i]));
        }

        var args = $.toJSON(rowsData, null, parameterName);

        _currentInsertState = new Object();
        _currentInsertState.callback = callback;
        _currentInsertState.gridName = gridName;
        _currentInsertState.saveUrl = saveUrl;
        _currentInsertState.parameterName = parameterName;

        $.post(saveUrl, args, _onAfterGridSave, "json");
    }
}

 

function gridSaveRows(gridName, saveUrl, parameterName, callback) {
    var currGrid = $("#" + gridName);
    var gridRows = _gridNewRows[gridName];
    var rowsData = new Array();
    var i;

    if (gridRows != undefined) {
        for (i = 0; i < gridRows.length; i++) {
            jQuery("#" + gridName).jqGrid('saveRow', gridRows[i], null, "clientArray");
            rowsData.push(currGrid.getRowData(gridRows[i]));
        }

        var args = $.toJSON(rowsData, null, parameterName);

        _currentInsertState = new Object();
        _currentInsertState.callback = callback;
        _currentInsertState.gridName = gridName;
        _currentInsertState.saveUrl = saveUrl;
        _currentInsertState.parameterName = parameterName;

        $.post(saveUrl, args, _onAfterGridSave, "json");
    }
}
Coordinator
Apr 28, 2011 at 9:21 AM

Fixed, thanks.

Though I'm wondering - should the gird post to the server anyway?