Title: create a copy button on datagrid Post by: dan on June 15, 2015, 07:50:12 AM Hi,
I'm trying to create a 'copy' button on datagrid so that a user can select a previous entry and then copy it to the database - similar to the edit function. The id is AI so this is the only value that I dont want to copy for obvious reasons, I think this can be done but I havent a clue to get it working. I've created the copy button ready but need to create the script. Any help is appreciated! Title: Re: create a copy button on datagrid Post by: dan on June 15, 2015, 08:34:47 AM UPDATE
I ran this code and it created the copy but the problem is the dialog box didnt close so I clicked the save button 3 times and it created 3 copies - does anyone know how to get it to close the dialog after save is hit and refresh the data? here's my code;- function copyDel(){ $('#dlg').dialog('open').dialog('setTitle','Copy Delivery Note'); $('#fm').form('clear'); url = '/functions/add/add_del_out.php'; } } Title: Re: create a copy button on datagrid Post by: stworthy on June 16, 2015, 12:31:43 AM To close a dialog, you need to call the 'close' method.
Code: $('#dlg').dialog('close'); Title: Re: create a copy button on datagrid Post by: dan on June 16, 2015, 03:21:30 AM Hi stworthy,
thanks but I am struggling to get that method to work. My code currently is;- function copyDel(){ var row = $('#dg').datagrid('getSelected'); if (row){ $('#dlg').dialog('open').dialog('setTitle','COPY Delivery Note'); $('#fm').form('load',row); url = '/add_del_out.php?id='+row.id; } } I tried to add your 'close' method at the end but I think this opens the dialog and then immediately closes it. I would have thought that once I clicked save it saved the data to the database and then cleared and closed the dialog. Any ideas? Title: Re: create a copy button on datagrid Post by: stworthy on June 16, 2015, 05:18:06 AM You do not paste your saving code but it may look like this.
Code: $.ajax({ Title: Re: create a copy button on datagrid Post by: dan on June 16, 2015, 05:27:26 AM You do not paste your saving code but it may look like this. Code: $.ajax({ Hi again, my saving code is;- function saveDel(){ $('#fm').form('submit',{ url: url, onSubmit: function(){ return $(this).form('validate'); }, success: function(result){ var result = eval('('+result+')'); if (result.errorMsg){ $.messager.show({ title: 'Error', msg: result.errorMsg }); } else { $('#dlg').dialog('close'); // close the dialog $('#dg').datagrid('reload'); // reload the user data } } }); } but I would have thought it should still close once the save button is clicked? The data gets added to the database ok |