EasyUI Forum
April 19, 2024, 05:45:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Multiple Delete from data grid  (Read 3860 times)
AJLX
Newbie
*
Posts: 17


View Profile
« on: July 03, 2018, 12:41:29 PM »

Hey guys,

I have the option to delete records from a datagrid. It gets a bit tedious when it comes to deleting multiple records. I have set the datagrid up with check boxes to appear, and can multi select them. The next part is where I get stuck. Is there a way that I can put the values into an array and send via AJAX to a php file? Could you help me with that?

Thanks,

EDIT:

So far I have tried to reuse a function found in one of the tutorials:

Code:
function test() {
        var ids = [];
        var rows = $('#dg').datagrid('getChecked');
        for(var i=0; i<rows.length; i++){
            ids.push(rows[i].id);
        }
        alert(ids.join('\n'));
        }

This seems like it should work, but the alert box is empty. If I could fill it, I could then use the loop to do multiple AJAX calls, unless there is a more sensible way?
« Last Edit: July 03, 2018, 01:09:52 PM by AJLX » Logged
AJLX
Newbie
*
Posts: 17


View Profile
« Reply #1 on: July 03, 2018, 03:37:42 PM »

I've solved this! I'm sure there is a more efficient way to do it though. My code is here in case it helps anyone else out

Code:
        function destroyProject(){
 
                var ids = [];
                var rows = $('#dg').datagrid('getChecked');
                for(var i=0; i<rows.length; i++){
                    ids.push(rows[i].row_id);
                }

                // We loop through each project and then delete it
                $.each(ids, function (index, value) {
                  $.post('destroy_project.php',{id:value},function(result){
                         
                          if (result.success){
                          } else {
                              $.messager.show({    // show error message
                                  title: 'Error',
                                  msg: result.errorMsg
                              });
                          }
                      },'json')
                }

                 
         
        );
                $('#dg').datagrid('reload');    // reload the user data

        }
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!