1
0
-1

We are trying to add a "copy button on every row of the grid". As opposed to a single button. This would be a variation of the https://dev.joget.org/community/display/DX7/Duplicate+Form+Grid Copy Grid 1 to Grid 2" a sample script that helps us copy all rows with a single button click.


The Usecase that I am trying to Handel is after coping with the Rows to the destination Grid the source grid data is updated.  and instead of coping with all rows, only the updated one will be copied over.


Not sure how to inject this into grid ?
<td><input type='button' class='cpRow' value='Copy Row Grid1 to Grid2'></td></tr>

<script>
$(function(){
    $(".cpRow").on("click", function() {
        var grid1 = FormUtil.getField("field1");
        var grid2 = FormUtil.getField("field2");
 
        $(grid1).find(".grid-row"){
            var json = $(this).find("textarea").val();
 
            //remove id
            var obj = JSON.parse(json);
            if (obj.id !== undefined) {
                delete obj.id;
                json = JSON.stringify(obj);
            }
 
            $(grid2).enterpriseformgrid("addRow", {result: json });
        });
    });
});
</script>
    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Thanks Walter for the answer but I think I have not explained my question or my use case so I will try to do that.

      I am trying to have two grids on a single Form. The source Grid Table is loaded via the JDBC query and is read-only on this form but more rows can be added via another form. The destination form is editable so the copied data can be enriched. 

      As an example, if the user comes to the screen for the first time there are 2 rows in the source table and the user copies those 2 rows using the script from the joget published example "Duplicate Form Grid". The user then proceeds to modify the records in the destination grid and save the 10 records.

      When the user subsequently comes to the form the second time there are two additional records. These two rows were added to the sources as a modification via another form / process.

      If we were to use the same button then we will have to First delete the existing 2 Rows in the destination Grid and need to redo all 4 rows.

      In order to solve this, I was thinking of adding a "Copy Row to Grid 2 " Button in every row of the source Gri would make it simple. 

      Below is the screenshot Illustrating my use case.  I would be really obliged if a sample code can be provided.



        CommentAdd your comment...
      1.  
        1
        0
        -1

        How do we determine which is " only the updated one will be copied over."? Once we can establish that, we should be able to loop thru all the rows and exclude them.

          CommentAdd your comment...