Author Topic: Adding new rows from existing rows  (Read 3047 times)

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
Adding new rows from existing rows
« on: December 01, 2017, 09:03:03 am »
For new rows , users want to copy existing rows and modify them.
so  I am adding new rows  from existing rows selected.

There are 2 problems with this code:
1. New rows when modified, there are same entries in addList and updateList.  - I want entry only in addList
2. When pasting is done on cell new rows , existing rows cells also show modified sign but they are modified. - I have no idea why that is happening.

Any help ?


Code: [Select]
function cloneRows() {

            var arr = $grid.pqGrid("selection", { type: 'row', method: 'getSelection' });
            console.log("getRowIndx");
            console.log(arr);
            if (arr && arr.length > 0) {
                for (var index = 0; index < arr.length; index++) {
                    var foo = arr[index].rowData;
                    var clone = Object.assign({}, foo);
                    clone.Id = -index;
                    clone.pq_rowcls = 'yellow';
                    var addIndx = $grid.pqGrid("addRow", { rowIndx: index, rowData: clone, checkEditable: false });
                    console.log("addIndx");
                    console.log(addIndx);
                }

                $grid.pqGrid("setSelection", null);
                $grid.pqGrid("refresh");
               
            }
            else {
                alert("Select a row.");
                return null;
            }
        }

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
Re: Adding new rows from existing rows
« Reply #1 on: December 01, 2017, 01:15:06 pm »
For new rows , users want to copy existing rows and modify them.
so  I am adding new rows  from existing rows selected.

There are 2 problems with this code:
1. New rows when modified, there are same entries in addList and updateList.  - I want entry only in addList
2. When pasting is done on cell new rows , existing rows cells also show modified sign but they are not modified and they still have existing value. - I have no idea why that is happening.

Any help ?


Code: [Select]
function cloneRows() {

            var arr = $grid.pqGrid("selection", { type: 'row', method: 'getSelection' });
            console.log("getRowIndx");
            console.log(arr);
            if (arr && arr.length > 0) {
                for (var index = 0; index < arr.length; index++) {
                    var foo = arr[index].rowData;
                    var clone = Object.assign({}, foo);
                    clone.Id = -index;
                    clone.pq_rowcls = 'yellow';
                    var addIndx = $grid.pqGrid("addRow", { rowIndx: index, rowData: clone, checkEditable: false });
                    console.log("addIndx");
                    console.log(addIndx);
                }

                $grid.pqGrid("setSelection", null);
                $grid.pqGrid("refresh");
               
            }
            else {
                alert("Select a row.");
                return null;
            }
        }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6264
    • View Profile
Re: Adding new rows from existing rows
« Reply #2 on: December 01, 2017, 03:33:26 pm »
When cloning rows, care should be taken to remove the primary key field (set it to undefined ) before adding them to pqgrid.

Also existing rows have meta data associated with them which should not be copied, so individual fields ( dataIndx ) should be copied from existing rows instead of copying everything from them.
« Last Edit: December 01, 2017, 04:25:16 pm by paramquery »