Author Topic: Save newly added rows and removed rows  (Read 2131 times)

Davjov

  • Newbie
  • *
  • Posts: 1
    • View Profile
Save newly added rows and removed rows
« on: September 05, 2019, 01:42:22 pm »
Hello,
when I edit data in a row, it is saved and passed on to the next application. But when I add or remove rows, they are not saved and displayed in the next application. What do I have to change with the following functions to make this possible?


   function addRow() {
   
                var $frm = $("form#crud-form");
                $frm.find("input").val("");
   
                $("#popup-dialog-crud").dialog({ title: "Eintrag Hinzufügen", buttons: {
                    Add: function () {
                        var row = [];
                        //save the record in DM.data.
                        row[0] = $frm.find("input[name='kategorie']").val();
                        row[1] = $frm.find("input[name='komponente']").val();
                        row[22] = $frm.find("input[name='summary']").val();
                       
                        $grid.pqGrid('addRow', { rowData: row });
                       
                        $(this).dialog("close");
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
               
                }
                });
                $("#popup-dialog-crud").dialog("open");
            }


And:

 function deleteRow() {
                var rowIndx = getRowIndx();
                if (rowIndx != null) {
                    $grid.pqGrid("deleteRow", { rowIndx: rowIndx });
                    $grid.pqGrid("setSelection", { rowIndx: rowIndx });
                }
            }
            function getRowIndx() {
                var arr = $grid.pqGrid("selection", { type: 'row', method: 'getSelection' });
                if (arr && arr.length > 0) {
                    return arr[0].rowIndx;                               
                }
                else {
                    alert("Wählen sie eine Reihe aus");
                    return null;
                }}


Thank for your help.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Save newly added rows and removed rows
« Reply #1 on: September 06, 2019, 11:59:49 am »
Added and removed rows are stored in addList and deleteList as below, these are sent to server for remote saving and changes are locally saved by commit method in the grid.

Code: [Select]
grid.getChanges({ format: "byVal" }).addList
grid.getChanges({ format: "byVal" }).deleteList

Example: https://paramquery.com/demos/editing_batch