Duplicate button
Duplicate button
I am trying to create a duplicate function, using the existing "Create" functionality and setting field defaults to existing values. I works fine, except for joined tables:
Here is the (not working button):
{
extend: 'selectedSingle',
text: '<i class="fa fa-clone"></i>',
action: function ( e, dt, node, config ) {
selected_user_site = table.cell(table.rows( { selected: true } ), 4).data();
editor
.create({
buttons: ['<i class="fa fa-save"></i>'],
})
.set(4, selected_user_site);
},
}
The problem lies with getting the value from the selected row. > table.cell(table.rows( { selected: true } ), 4).data() returns "Singapore" instead of the underlying value "5".
Answers
Does this mean the cell contains a
select
element?You may need to use
cell().node()
to get the value of the select input, for example:If this doesn't help then please provide a simple test case showing what is contained in the cells so we can offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I've reproduced on the live.datatables.net site:
https://live.datatables.net/paduwane/1/
When you select the second record and click on duplicate, the console shows "London", instead of the underlying value 2.
Using the node() doesn't work either, as it refers to the <td> element, rather than the select option.
I see, you are using the Editor. I think you will need to use Editor API's to get the select value. One option is to use
edit()
withget()
, for example:https://live.datatables.net/paduwane/2/edit
There may be other / better ways to do this.
Kevin
I use a "duplicate" button too. It is based on something Allan posted somewhere a while ago.
The following button copies a "selected" record ("select" extension required!), edits it and switches to "create" mode. It does not copy the files associated with the copied record. And it sets a couple of global variables that I need for certain things
Maybe that helps.
This is how I use it in "buttons":
Thank you!
@kthorngren answer did the trick!
I will test @rf1234's a bit later. Thanks also.