EasyUI Forum
June 25, 2024, 09:58:24 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: create a copy button on datagrid  (Read 9009 times)
dan
Newbie
*
Posts: 17


View Profile
« 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!
Logged
dan
Newbie
*
Posts: 17


View Profile
« Reply #1 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';
      }

      }
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 on: June 16, 2015, 12:31:43 AM »

To close a dialog, you need to call the 'close' method.
Code:
$('#dlg').dialog('close');
Logged
dan
Newbie
*
Posts: 17


View Profile
« Reply #3 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?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: June 16, 2015, 05:18:06 AM »

You do not paste your saving code but it may look like this.
Code:
$.ajax({
url:...
//...
success:function(){
$('#dlg').dialog('close');
}
})
Logged
dan
Newbie
*
Posts: 17


View Profile
« Reply #5 on: June 16, 2015, 05:27:26 AM »

You do not paste your saving code but it may look like this.
Code:
$.ajax({
url:...
//...
success:function(){
$('#dlg').dialog('close');
}
})

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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!