Update Original Row After Duplicate

Update Original Row After Duplicate

LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0

I'm using Editor's Duplicate button - https://editor.datatables.net/examples/api/duplicateButton.html to create a new row that's based on an existing row. I'm stumped on one piece of functionality - updating the original record to indicate that it was duplicated.

If we really got fancy, I need to take a value from the duplicate row and update a column on the original. For instance, if the original row had a StartDate of January and no EndDate, once I create a duplicate with a StartDate of March, I need to update the original to have an EndDate of March.

Does anyone have any examples of this functionality, or can you please point me in the right direction?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    For instance, if the original row had a StartDate of January and no EndDate, once I create a duplicate with a StartDate of March, I need to update the original to have an EndDate of March.

    Are you updating to March as part of the duplication process? Or at some point in the future after duplicating?

    Also, have you limited the user to only duplicating a single record? Or can they duplicate many?

    Colin

  • LmtarboxLmtarbox Posts: 9Questions: 3Answers: 0
    edited May 2020

    I'm updating as part of the duplication process. So the button opens the editor form and uses the create action like this ->

    {
                        extend: "selected",
                        text: 'Duplicate',
                        action: function (e, dt, node, config) {
                            // Start in edit mode, and then change to create
                            editor
                                .edit(table.rows({ selected: true }).indexes(), {
                                    title: 'Duplicate record',
                                    buttons: 'Create from existing'
                                })
                                .mode('create');
                        }
                    },
    

    When the editor window pops up, the user can make changes to any fields, and will add a StartDate as part of that process before clicking "Create from existing"

    I'm focusing on duplicating a single record right now.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    This should here help you along. If the office field is changed from the original, then it gets updated in the duplicate. It's not quite the same as your requirements, but it demonstrates how the old and new records can be accessed and manipulated.

    Hope that does the trick,

    Colin

This discussion has been closed.