add a duplicate button in-table style
add a duplicate button in-table style
Mike-motiv8
Posts: 30Questions: 5Answers: 0
I am struggling to add a Duplicate button as a in-table style.
the code i have so far is:
$('#songsTable').on("click", "Duplicate", function(e, dt, node, config){
var data = table1.row$(this).parents('tr')).data();
delete data.DT_RowId;
editor2.create().set(data).submit();
});
the button is listed under the colums tag with:
{ targets: -1,
data: null,
// defaultContent: '<a href="" class="Bin">Delete</a>'
defaultContent: "<button>Duplicate</button>",
},
Could somebody please point me in the right direction, or even provide me with a correction.
Thanks in advance
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm guessing the problem is the click event isn't firing?
The word
Duplicate
doesn't look like a valid jQuery selector in the click event:.on("click", "Duplicate"
. See if this example helps:http://live.datatables.net/xijecupo/1/edit
Kevin
Hi @Mike-motiv8 ,
Here's the inline version - using a combination of the first solution and Kevin's code.
Cheers,
Colin
Thank you Kevin and Colin,
Support here is amazing.
I never thought of using a class attribute to fire the code. Which handy as i could use the 'a' attribute and use a small jpg.
When i click duplicate, i see a edit modal box appear on screen for a short second.
i have tried using. draw(false) but does not effect it.
is this normal? As it is annoying on mobiles.
Hi @Mike-motiv8 ,
Could you link to a test case, or your page, that's showing that issue, please, as it's not occuring on the links that I've posted.
Cheers,
Colin
the database is here:
https://www.motiv-8.co.uk/clients/clientRequests.php
press a green button and you will see the modal pop up.
Also I struggling to find information on custom values with duplicate record.
I have a DB field called Tableno.
When the duplicate (green) is pressed, I would like a number "1" passed to the Tableno field in the DB.
I have tried, def: "1" and value: "1" without success within the column code.
It does however populate the modal Tableno field, but is not recorded to the DB.
I also can not get the:
$editor->where( 'Tableno', 1 );
to work, or even without the $editor
How do you use a where clause? Where everything in Tableno field = 1
Can you show me your PHP code then please?
. How do you use a where clause?
The code above is not valid PHP and should be throwing a syntax error.
You want to add
->where( 'Tableno', 1 )
immediately before the->process(...)
method call.Allan
hi Allan,
yes i realised the where clause goes immediately before the process line.
I thankfully found the answer on here, tucked within another thread.
I will show the php later.
I still can not fathom why I'm seeing a modal flash on screen when I duplicate records?
Is that shown on your link above? I don't see a "Duplicate" button there.
Allan
The duplicate buttons are the green, orange and red buttons on each line of the main table. I have used in-table image duplicate buttons. which fill the three tables on the right
You are using:
Which is fine, but
create()
will show the form by default which is why it flashes up. When the submit completes it is then hidden.If you want the form hidden
create()
has ashow
option:Allan
I look at that page too. But I missed it. Thank You again Alan.
How do I apply for a free licence extension until Monday, once i'm back in my office? If this isn't possible - No worries.
editor2.create(false).set(data).submit();
Has broken my validation message for duplicate records, which is on my ajax php page.
Field::inst( 'ID' )
->validator( 'Validate::unique', array(
"required" => true,
"message" => "The song has benn requested."
) ),
Is there another way of popping up a modal to inform the user that the record already exists?
Listen for
submitComplete
and check for error messages in the returned data. If there is, then show the error message. The API was designed that if you are hiding the Editor form, then it would expect you to show the error messages if there are any.Allan