More on jqGrid and getRowData function in edit mode

I blogged a while back on shortcoming of getRowData function of jqGrid in edit mode.  I also recently ran into an issue when getRowData was returning blank for a cell that contains select (dropdown) control in edit mode.  So, I wrote a quick function that I wanted to post here to help others that handles both situations (the best it can in the case of a blank).


window.jqHelpers = window.jqHelpers ||
    parseValueFromJQGridCell: function (celValueReturndByGetRowData, columnName, handleBlanks) {
        var controlNameToLookFor = new RegExp("id=".+_" + columnName, "ig");
        var finalValue = celValueReturndByGetRowData;
        if (celValueReturndByGetRowData.toLowerCase().indexOf('<input') >= 0 || celValueReturndByGetRowData.toLowerCase().indexOf('<select') >= 0) {
            var matched = finalValue.match(controlNameToLookFor)[0];
            var rowIndex = matched.toUpperCase().replace("ID="", "").replace("_" + columnName.toUpperCase(), "");
            finalValue = $('#' + rowIndex + '_' + columnName).val();
        if (!finalValue && handleBlanks) {
            var inputControl = $('input[id*=' + columnName);
            if (inputControl.length) {
                finalValue = inputControl.val();
        if (!finalValue && handleBlanks) {
            var selectControl = $('select[id*=' + columnName);
            if (selectControl.length) {
                finalValue = selectControl.val();
        return finalValue;

The idea is that after you call getRowData, you would run through the returned array and only for columns that are editable call the function, such as

oneRow[‘ColumnName’] = jqHelpers.parseValueFromJQGridCell(oneRow[‘ColumnName’], ‘ColumnName’, true);


Leave a Reply

Your email address will not be published. Required fields are marked *