Author Topic: How to delete all row in grid  (Read 3195 times)

bsolteam

  • Pro Deluxe
  • Full Member
  • *
  • Posts: 107
    • View Profile
How to delete all row in grid
« on: December 08, 2014, 07:27:16 pm »

Hi,
    I can't able to delete first row in a grid. I can delete remaining all. After delete when i click save on that time only data will delete in database. I am using the following code for delete,


       remove : function(vslname) {            
            var $grid = $("#off_hire_tab");
            var data = $grid.pqGrid('option', 'dataModel.data');         
           var status = 0;
            if(data[data.length - 1].fixture_id== 000 && data[data.length - 1].acct_period== 000 && data[data.length - 1].from_Date== 000 && data[data.length - 1].to_Date== 000 && data[data.length - 1].offhire_id== 000)
             {
                
             }            
             if(data.length  != 0)
             {
            
                if(data[data.length - 1].fixture_id== 000 && data[data.length - 1].acct_period== 000 && data[data.length - 1].from_Date== 000 && data[data.length - 1].to_Date== 000 && data[data.length - 1].offhire_id== 000)
                {
                   deleteList = "";
                   isAdded = null;
                }
                else
                {                   
                   data[0].deleteList += data[data.length - 1].fixture_id+"," +data[data.length - 1].acct_period+"," + data[data.length - 1].from_Date+"," + data[data.length - 1].to_Date+"," + data[data.length - 1].offhire_id+",";         
                   data[0].isDeleted = "Y";   
                   
                   //alert("this is the delette list "+data[0].deleteList);
                }
                $grid.pqGrid( "deleteRow", { rowIndx: data.length - 1 } );                 
             }
              else
             {
                $('div.jGrowl').find('div.jGrowl-notification').parent().remove();
                $.jGrowl("OffHire cannot be deleted", { sticky: false });              
               exit;
             }


After remove the record i am going to save. the following code is for save,


        if(deleteList.length != 0)
                       {
                      var dList = data[0].deleteList.slice(9);
                     data[0].deleteList = dList;               
                     dList = dList.substring(0, dList.length - 1);                  
                     $.ajax({
                        type : 'GET',
                        url : "deleteOffhire",
                        data : "dList="+dList,
                        contentType : "application/json; charset=utf-8",
                        success : function(response) {                  
                           if (response == true) {
                              $('div.jGrowl').find('div.jGrowl-notification').parent().remove();
                              $.jGrowl("Data was successfully Deleted", {
                                 sticky : false                        
                              });                        
                              $("#off_hire_tab").pqGrid("refreshDataAndView");
                           }
                        },
                        error : function(e) {                  
                        },
                     });               
                     $("#off_hire_tab").pqGrid("refreshDataAndView");            
                  }   
                     
                  },         
               };

Please help me, here how can i delete one or more records. I cant able to delete the first record.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: How to delete all row in grid
« Reply #1 on: December 09, 2014, 02:43:34 pm »
It's not clear what you are trying to do in your code, please follow the online demos for how to delete rows and provide a jsfiddle if still facing issues.