Duplicate button functionality using Editor Ajax not working as expected

Duplicate button functionality using Editor Ajax not working as expected

dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

I have a weird issue with the duplicate button:

I have this:

buttonsArray.push({
    extend: "selectedSingle",
    text: 'New',
    action: function (e, dt, node, config) {

        _editor
            .edit(_table.rows({ selected: true }).indexes(), {
                title: 'Duplicate record',
                buttons: 'Create from existing'
        })
        .set('Condition', "")
        .mode('create');
    }
);

And I have my ajax function like this:

ajax: {
  url: 'api/DT_Condition/Condition/',
  data: function (d) {
    var id = Number(d.data[Object.keys(d.data)[0]].ID);
    d.data[id].Selection = vm.project_data.ProjectName;
    var retVal = false;
    if (d.data[id].Trimmed != null) {
      retVal = d.data[id].Trimmed[0]
    }
    return JSON.stringify(d);
  },
  contentType: "application/json",
  success: function (jsonData) {
    console.log(jsonData);

  }
}

Using this ajax call, edit, delete, and create all works as expected. However, what's really irking me, is the Duplicate functionality. The Duplicate function works as expected, it copies all values, and saves it as a new record. However, if I was to Duplicate the same record I previously selected, or even if I Edit the previously selected row, it copies what was saved previously onto the popup, not the values of the selected row. Even though the row on the table has not changed.

So for example, if I select row 1 that has ColumnA: "Square" , ColumnB: "John Doe", ColumnB: "House"
Then I duplicate this record to: ColumnA: "Circle", ColumnB: "John Doe", ColumnC: "Ground"

A new record is added as expected.

If I select row 1 again, and whether or not I click the Duplicate button or the Edit button it gives me these values:
ColumnA: "Circle", ColumnB: "John Doe", ColumnC: "Ground"

instead of what's shown in the row
ColumnA: "Square" , ColumnB: "John Doe", ColumnB: "House"

Again, the server format is correct, because the edit, create, and remove functionality works. It's utilizing the handshack mentioned here: https://editor.datatables.net/manual/server

So I do get back:

{
    "data": [
    {
        "DT_RowId": "row_29",
        "ColumnA": "Square",
        "ColumnB": "John Doe",
        "ColumnC": "Ground",
    }
  ]
}

Is there something I'm doing wrong? Because in order to fix this, I have to ajax reload the table every time I duplicate a record in order for it to work properly.

Answers

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    I do want to mention, this only happens to the record I duplicated from.. not any other record.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The example here appears to be working as expected for me. Are you able to reproduce the problem there or give me a link to a page showing the issue please?

    Allan

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    I'm not sure what I'm doing wrong then.. I'm doing the same thing, and getting the same kind of response.

    I'm also using the latest library as well. Maybe it has to do something with the latest update, because I didn't notice this until after I updated the libraries.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi Dan,

    I tried it with the most recent releases, and was unable to reproduce. Would you be able to link to your page, or create a test case, so that we can progress this?

    Cheers,

    Colin

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    This will take some time.. but I will try. I just have stuff I have to finish first though.

This discussion has been closed.