Author Topic: Auto Save Add Problem  (Read 2775 times)

angelahlp

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
Auto Save Add Problem
« on: July 24, 2015, 11:29:13 am »
I used the Autosave Demo as a template and am having problems getting the Add to work. When I click the add button, I get a new row and can enter information. As soon as all required fields are entered the save happens, then if any other fields are entered it creates a new record with the same values as the record that was saved after the required fields were entered - instead of modifying the new record.

Essentially, nothing is saved until all the required fields are entered, but as I enter other fields in the new row, new records are created and I end up with 2+ records with the same information - each new one has one more field defined. I assume there is an issue with the commit as it seems that the id remains at zero (0) even after the commit.

It also allows me to move out of the new row before all the required fields are entered - which doesn't happen in the demo.

The code I have is as follows:

ADD BUTTON:
----------------------------------------
 toolbar: {
                cls: "pq-toolbar-search",
                items: [                   

                    { type: 'button', icon: 'ui-icon-plus', label: 'New Product', listener:
                        { "click": function (evt, ui) {
                            //append empty row at the end.                           
                            var rowData = { movedate: '', movetime: '', namefield: 'Enter Inject', injectnumber: '', simulatedresourcename: '', simulatedresourceid: '', playingresourcename: '', playingresourceid: '', commandid: '', command: '', usingwhatid: '', usingwhat: '', expectedplayeraction: '', messageimplementor: '' }; //empty row
                            var rowIndx = $grid.pqGrid("addRow", { rowData: rowData });
                            $grid.pqGrid("goToPage", { rowIndx: rowIndx });
                            $grid.pqGrid("setSelection", null);
                            $grid.pqGrid("setSelection", { rowIndx: rowIndx, dataIndx: 'moveid' });
                            $grid.pqGrid("editFirstCellInRow", { rowIndx: rowIndx });
                        }
                        }
                    },
etc. .....
---------------------------------------------------------------------------
CHANGE CODE:


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

                for (var i = 0; i < rowList.length; i++) {
                    var obj = rowList,
                        rowIndx = obj.rowIndx,
                        newRow = obj.newRow,
                        type = obj.type,
                        rowData = obj.rowData;

                    if (type == 'add') {
                        var valid = grid.isValid({ rowData: newRow, allowInvalid: false }).valid;
                        if (valid) {
                            addList.push(newRow);
                        }
                    }
                    else if (type == 'update') {
                        var valid = grid.isValid({ rowData: rowData, allowInvalid: false }).valid;
                        if (valid) {
                            if (rowData[recIndx] == null || rowData[recIndx] == '') {
                                addList.push(rowData);
                            }
                            //else if (grid.isDirty({rowData: rowData})) {
                            else {
                                updateList.push(rowData);
                            }
                        }
                    }
                    else if (type == 'delete') {
                        if (rowData[recIndx] != null) {
                            deleteList.push(rowData);
                        }
                    }
                }
         if (updateList.length) {
            $.ajax({
               context: $grid,
               url: "/cfc/MSELConsole.cfc?method=updateInjectMatrix",
               data: "jsonstring=" + escape(JSON.stringify(updateList)),
                    dataType: "json",
                    type: "POST",
                    async: true,
                    beforeSend: function (jqXHR, settings) {
                        $(".saving", $grid).show();
                    },
               success: function (rows) {
                  $grid.pqGrid("commit", { type: 'update', rows: rows });
               },
                    complete: function () {
                        $(".saving", $grid).hide();
                    },
               error: function(jqXHR, exception){
                  alert('closing - updatelist - ' + jqXHR.responseText + ":" + exception);
               }

            });
         }
         if (addList.length) {
            $.ajax({
               context: $grid,
               url: "/cfc/MSELConsole.cfc?method=addInjectMatrix",
               data: "jsonstring=" + escape(JSON.stringify(addList)),
                    dataType: "json",
                    type: "POST",
                    async: true,
                    beforeSend: function (jqXHR, settings) {
                        $(".saving", $grid).show();
                    },
               success: function (rows) {
                  $grid.pqGrid("commit", { type: 'add', rows: addList });
               },
                    complete: function () {
                        $(".saving", $grid).hide();
                    },
               error: function(jqXHR, exception){
                  alert('closing - addlist - ' + jqXHR.responseText + ":" + exception);
               }

            });
         }

         if (deleteList.length) {
            $.ajax({
               context: $grid,
               url: "/cfc/MSELConsole.cfc?method=deleteInject",
               data: "jsonstring=" + escape(JSON.stringify(deleteList)),
                    dataType: "json",
                    type: "POST",
                    async: true,
                    beforeSend: function (jqXHR, settings) {
                        $(".saving", $grid).show();
                    },
               success: function (rows) {
                  $grid.pqGrid("commit", { type: 'delete', rows: rows  });
               },
               complete: function () {
                        $(".saving", $grid).hide();
               },
               error: function(jqXHR, exception){
                  alert('closing - deletelist - ' + jqXHR.responseText + ":" + exception);
               }

            });
         }

            },
etc......
------------------------------------------------------------------------

The JSON passed back for the commit on the Add is:
[{"playername":"Ambulance 511 (A511)","moveid":20579,"usingwhat":"","storylineid":"","simulatorname":"10,000 body bags ","namefield":"asdf aser ase rfaser asdf asdf sdaf","injectnumber":789,"playerid":1428,"movedate":"2/24/13","movetime":"12:44","usingwhatid":"","simulatorid":2891,"commandid":16,"movestatus":"Open","movestatusid":2,"expectedplayeraction":"","storyline":"","command":"ExPA","messageimplementor":""}]


--------------------

I also posted this and it was moved to the "Evaluation" thread - I got an answer that fixed my issue with the "edit" and "delete" button issues, but nothing about this. That post includes many file attachments that may help also. I won't attach here again.

Please let me know what else you need to help me with this issue.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6260
    • View Profile
Re: Auto Save Add Problem
« Reply #1 on: July 24, 2015, 12:07:12 pm »
As server side interaction is involved, we can't reproduce the issue mentioned by you.

Please provide a jsfiddle so that the mentioned issue can be seen and troubleshooted. Please replace the server side response by local JSON data.

Please use this jsfiddle as it includes all the dependencies.

http://jsfiddle.net/kw77c0sg/2/
« Last Edit: July 24, 2015, 03:26:48 pm by paramquery »