Duplicate button for multiple selected rows is only updating rows

Duplicate button for multiple selected rows is only updating rows

BROB201BROB201 Posts: 28Questions: 4Answers: 0

https://editor.datatables.net/examples/api/duplicateButton.html

using the example, I added the button to duplicate selected rows.

action: function(event, datatable, node, config) {
    editor.edit(
        datatable.rows({selected: true}).indexes(),
        {
            title: 'Copy record',
            buttons: 'Create from existing'
        }
    ).mode('create');
},

ajax options for editor:

edit: {
    type: 'PUT',
    url: '/api/hifCableRequestRow',
    data: function (data) {
        return JSON.stringify(data.data);
    },
    "contentType": "application/json"
},
remove: {
    type: 'DELETE',
    url: '/api/hifCableRequestRow',
    data: function (data) {
        var crfkeys = [];
        for (var crf in data.data) {
            crfkeys.push(crf);
        }
        return {'crfkeys': crfkeys};
    }
},
create: {
    type: 'POST',
    url: '/api/hifCableRequestRow',
    data: function (data) {
        return JSON.stringify(data.data);
    },
    "contentType": "application/json"
}

request

{123123: {...}, 123124: {...}, ...}

If I select multiple rows, and click the new copy button, it sends a PUT request instead of a POST request. Any thoughts on what I might be doing wrong? Perhaps this is intended and I just need to make my server handle that payload as a create? How can I distinguish the requests?

This question has an accepted answers - jump to answer

Answers

  • BROB201BROB201 Posts: 28Questions: 4Answers: 0

    Actually, I looked in the editor javascript file and noticed that the mode function takes no parameters, so I checked the release notes, and it appears that was added to 1.7. I will update my code first, and likely close this question

  • BROB201BROB201 Posts: 28Questions: 4Answers: 0

    Updating my Editor code to 1.7 fixed the issue. I would recommend adding a version to the linked example, but thanks for the fancy copy functionality!

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    The behaviour of that example has changed slightly in 1.7 as mode() can now be used as a setter - i.e. change the edit action into a create. So the key difference is that the action submitted is create.

    it should really use POST given your Ajax configuration there. Let me check into that.

    Allan

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    I've just tried this locally, and using the mode() method as a setter does appear to work okay when ajax is given as an object.

    Allan

This discussion has been closed.