Duplicate button for multiple selected rows is only updating rows
Duplicate button for multiple selected rows is only updating rows
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
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
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!
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 theactionsubmitted iscreate.it should really use
POSTgiven your Ajax configuration there. Let me check into that.Allan
I've just tried this locally, and using the
mode()method as a setter does appear to work okay whenajaxis given as an object.Allan