Author Topic: Sending editable: false Columns Remotely When Adding Row  (Read 3438 times)

SMV93

  • Newbie
  • *
  • Posts: 8
    • View Profile
Sending editable: false Columns Remotely When Adding Row
« on: October 31, 2017, 12:36:58 am »
I have a pqGrid based off of the Auto Save Demo.

I'm having issues sending non-editable columns to a remote location when adding a row and when updating a newly added row. It only sends the editable columns to the remote location. I need to send back all the columns for primary key ID indexing and accounting calculations. This is not an issue with existing rows. Which setting needs to be added/changed for the grid to always send all of the columns to the remote location?

SMV93

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Sending editable: false Columns Remotely When Adding Row
« Reply #1 on: November 03, 2017, 02:14:23 am »
I've attached a screenshot the console.log(ui) of my pqGrid when I add a row. On the top you can see what is being sent to the server and on the bottom what is being returned from the server. EquipmentID, Depreciation_Years, and Net_Book_Value are not being sent back to the server. These columns are editable: false because the server auto-assigns or auto-calculates those values. I need to send these columns back to the server or else pqGrid is not updated correctly and leads to another row being added whenever the newly added row is updated. Creating a postback or a refreshDataAndView patches the issue, but that causes the undo/redo buttons to not function.

I have a different pqGrid where the ID is also editable: false and it does not have this issue. The add, update, delete codes are the same for both grids. The only real difference between the two is the column model.

SMV93

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Sending editable: false Columns Remotely When Adding Row
« Reply #2 on: November 08, 2017, 01:41:09 am »
I found the issue is related to grid.commit not being triggered when the row is returned from the server. This causes the recIndx to not be updated. Are there certain conditions that would cause commit to not be triggered? Possibly related to the colModel? I have another pqGrid with the same change code and it works flawlessly. The only major difference between the two grids is the colModel.

This is my change code related to commit:

Code: [Select]

                change: function (evt, ui) {
                    console.log(ui.source);
                    if (ui.source == 'commit' || ui.source == 'rollback') {
                        return;
                    }
                    console.log(ui);
                    var $grid = $(this),
                        grid = $grid.pqGrid('getInstance').grid;
                    var rowList = ui.rowList,
                        recIndx = grid.option('dataModel').recIndx,
                        addList = [],
                        updateList = [],
                        deleteList = [];

                    for (var i = 0; i < rowList.length; i++) {
                        var obj = rowList[i],
                            rowIndx = obj.rowIndx,
                            newRow = obj.newRow,
                            type = obj.type,
                            rowData = obj.rowData;
                        if (type == 'add') {
                            var valid = grid.isValid({ rowData: newRow, allowInvalid: true }).valid;
                            if (valid) {
                                addList.push(newRow);
                            }
                        }
                        else if (type == 'update') {
                            var valid = grid.isValid({ rowData: rowData, allowInvalid: true }).valid;
                            if (valid) {
                                if (rowData[recIndx] == null) {
                                    addList.push(rowData);
                                }
                                else {
                                    updateList.push(rowData);
                                }
                            }
                        }
                        else if (type == 'delete') {
                            if (rowData[recIndx] != null) {
                                deleteList.push(rowData);
                            }
                        }
                    }
                   
                    if (addList.length || updateList.length || deleteList.length) {

                        var passBack = JSON.stringify({
                            addList: addList,
                            updateList: updateList,
                            deleteList: deleteList
                        });

                        $.ajax({
                            async: true,
                            url: "EquipmentListWS.asmx/BatchGridEQL",
                            type: "POST",
                            dataType: "json",
                            contentType: 'application/json; charset=utf-8',
                            data: JSON.stringify({ list: passBack }),
                            success: function (changes) {
                                var jsonData = JSON.parse(changes.d);
                                //Uncomment following logs for code development
                                console.log(JSON.parse(passBack));
                                console.log(jsonData);

                                //commit the changes
                                grid.commit({ type: 'add', rows: jsonData.addList });
                                grid.commit({ type: 'update', rows: jsonData.updateList });
                                grid.commit({ type: 'delete', rows: jsonData.deleteList });
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                console.log(jqXHR);
                                console.log(textStatus);
                                console.log(errorThrown);
                            }
                        });
                    }
                },
« Last Edit: November 08, 2017, 04:13:54 am by SMV93 »

SMV93

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Sending editable: false Columns Remotely When Adding Row
« Reply #3 on: November 10, 2017, 06:15:15 am »
This issue is grid.commit not firing when the colModel allows nullable numbers. Sending editable: false columns back to the server is not the issue.

When adding a blank row, nullable number values have to be added to rowData as null or grid.commit will not fire. Example code below.

Code: [Select]
var rowIndx = $grid.pqGrid("addRow", { rowData: {
   //Handle nullable number values
   Purchase_Price: null,
   Rate_Per_Hour: null,
   Sell_Price: null,
   Year_Model: null
}

In addition, editable: false, dataType: "float" columns had to be changed to dataType: "string" to fire grid.commit.

Code: [Select]
                    {
                        title: "Depreciation Years", dataType: "string", dataIndx: "Depreciation_Years", width: 100, editable: false,
                        render: function (ui) {
                            var cellData = ui.cellData;
                            var rowData = ui.rowData[2];
                            console.log(rowData);
                            if (cellData != null && cellData != "") {
                                return parseFloat(ui.cellData).toFixed(2);
                            }
                        }
                    },

                    {
                        title: "NBV", dataType: "string", dataIndx: "Net_Book_Value", width: 100, align: 'right', editable: false,
                        render: function (ui) {
                            var cellData = ui.cellData;
                            if (cellData != null && cellData != "") {
                                return "$" + parseFloat(ui.cellData).toFixed(2);
                            }
                        }
                    },


After these changes grid.commit fires when addList is returned. This allows the recIndx to be updated and eliminates primary key issues.
« Last Edit: November 10, 2017, 06:18:04 am by SMV93 »