0 Replies Latest reply on May 5, 2009 9:10 PM by sathiyabala

    Deleting A Row From Datagrid

    sathiyabala Level 1

      Hai

       

          I have pasted the mxml below, because i am unable to attach the mxml, pl copy this below file into flex and run the application.

       

        1. Run the application.

       

        2. Enter values in the textbox and click add, values will be added to the datagrid.

       

        3. now click AND or OR and then change the values in the second and thrid combobox and again click add.

       

        4.Like wise change the combobox values and add five rows to the datagrid.

       

      5.now if u delete the last row u can see the curent last row in the combobox, so that the AND or Or can be added to it

       

      6. now if u delete a row in between, the deleted row's value oly maintains in the combobox,so i am unable to add AND or Or to the grid

       

        7.I need the last row data in the datagrid to be in the second and third combobox, which ever row is deleted.

       

       

       

       

      Can anyone help me....

       

       

      Thanks in advance.

       

      This is the mxml for sample

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>

      <![CDATA[
       
        // ActionScript file
      import mx.rpc.events.FaultEvent;
      import mx.controls.Alert;
              import mx.managers.CursorManager;
      import mx.collections.ArrayCollection;
      [Bindable]

       

      public var adhoc:ArrayCollection = new ArrayCollection();
      [Bindable]
      public var serverString = "" ; 
           
           
            private function initImage(event:MouseEvent):void {
           
                    if(adhoc.length > 0){
                  CursorManager.setBusyCursor();
                    }
                   
            }
         
         
                private function onChange():void{
           
            if(comboBox.selectedIndex == 0){

          }else{
               
            }
          }
         
       
                private function onChange1():void{

       

                if(combo2.selectedItem == "DATEDEPLOYED" || combo2.selectedItem == "DATEUPLOADED"){
                  datepick.visible = true
                  txt.visible = false
                }else{
                txt.visible = true
                  datepick.visible = false
                }
               
          }
       
          private function add():void{
       
          var str:String = txt.text;
          if(str.length == 0 && txt.visible == true){
              Alert.show("Value Can Not Be Empty");
              return;
            }     
         
            if(combo2.selectedItem != "DATEDEPLOYED" || combo2.selectedItem != "DATEUPLOADED"){
             
                if(txt.visible == true){
                    var temp:Object = new Object();
          temp.fname = combo2.selectedItem;
          temp.opera = combo1.selectedItem;
          temp.val = "'"+txt.text+"'";
              adhoc.addItem(temp);
                txt.text = "";
                }
            }
           
            var str1:String = datepick.text;
            if(comboBox.selectedIndex == 1){
              if(combo2.selectedItem == "DATEDEPLOYED" || combo2.selectedItem == "DATEUPLOADED"){
              if(str1.length == 0 && datepick.visible == true){
              Alert.show("Date Cannot Be Empty");
              }else{
              var temp:Object = new Object();
          temp.fname = combo2.selectedItem;
          temp.opera = combo1.selectedItem;
          temp.val = datepick.text;
                adhoc.addItem(temp);
                datepick.text = "";                   
              }
              }
          }

       

          addbutton.enabled = false;
          addopenbracket.enabled = false;
          combo2.enabled = false;
          combo1.enabled = false;
              }
                 
          private function querydelete():void{
             
              if (AdHoc.selectedIndex > 0) {
                  if(AdHoc.selectedIndex == (adhoc.length-1)){
                adhoc[AdHoc.selectedIndex-1].cond = "";
                addopenbracket.enabled = false;
                addclosebracket.enabled = false;
                addbutton.enabled = false;
                combo2.enabled = false;
                combo1.enabled = false;
                }
                combo2.selectedItem = adhoc[adhoc.length-2].fname
                combo1.selectedItem = adhoc[adhoc.length-2].opera
                  adhoc.removeItemAt(AdHoc.selectedIndex);
            //  adhocdetailgridcompilance.dataProvider = null ;
          //    adhocdetailgrid.dataProvider = null ;
                 
              }else if (adhoc.length == 1) {
                  adhoc.removeItemAt(AdHoc.selectedIndex);
            //  adhocdetailgridcompilance.dataProvider = null ;
          //    adhocdetailgrid.dataProvider = null ;
                  addopenbracket.enabled = true;
                addclosebracket.enabled = true;
                addbutton.enabled = true;
                combo2.enabled = true;
                combo1.enabled = true;
              }else{
                  Alert.show("Select The Rows To Delete");
              }
             
           
                 
              }
         
            private function andSubmit():void{
           
              for each(var obj:Object in adhoc){
                  if(obj.fname == combo2.selectedItem && obj.opera == combo1.selectedItem){
                    if(combo2.selectedItem != "DATEDEPLOYED" || combo2.selectedItem != "DATEUPLOADED"){
                  if(txt.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = and.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                  }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + "'"+txt.text+"'");             
                    }
                  }
                }else if(obj.fname == addclosebracket.label){
                  if(combo2.selectedItem != "DATEDEPLOYED" || combo2.selectedItem != "DATEUPLOADED"){
                  if(txt.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = and.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                  }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + "'"+txt.text+"'");             
                    }
                  } 
                } 
               
                if(obj.fname == combo2.selectedItem && obj.opera == combo1.selectedItem){
                  if(combo2.selectedItem == "DATEDEPLOYED" || combo2.selectedItem == "DATEUPLOADED"){
              if(datepick.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = and.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                  }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + datepick.text);             
                    }
                    }
                  }else if(obj.fname == addclosebracket.label){
                  if(combo2.selectedItem == "DATEDEPLOYED" || combo2.selectedItem == "DATEUPLOADED"){
                  if(txt.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = and.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                  }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + datepick.text);             
                    }
                }
              }
            }
            addbutton.enabled = true;
            addopenbracket.enabled = true;
            combo2.enabled = true;
            combo1.enabled = true;
            }

       

          private function orSubmit():void{

       

            for each(var obj:Object in adhoc){
                  if(obj.fname == combo2.selectedItem && obj.opera == combo1.selectedItem){
                    if(combo2.selectedItem != "DATEDEPLOYED" || combo2.selectedItem != "DATEUPLOADED"){
                  if(txt.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = or.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + "'"+txt.text+"'");             
                    }
                  }
                }else if(obj.fname == addclosebracket.label){
                  if(combo2.selectedItem != "DATEDEPLOYED" || combo2.selectedItem != "DATEUPLOADED"){
                  if(txt.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = or.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                  }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + "'"+txt.text+"'");             
                    }
                  } 
                } 
                 
                if(obj.fname == combo2.selectedItem && obj.opera == combo1.selectedItem){
                  if(combo2.selectedItem == "DATEDEPLOYED" || combo2.selectedItem == "DATEUPLOADED"){
              if(datepick.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = or.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
            }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + datepick.text);             
                    }
                    }
                  }else if(obj.fname == addclosebracket.label){
                  if(combo2.selectedItem == "DATEDEPLOYED" || combo2.selectedItem == "DATEUPLOADED"){
                  if(txt.visible == true){
                    trace("2 equals");
                    var temp:Object = new Object();
                    obj.cond = or.label
                    adhoc.setItemAt(obj,adhoc.getItemIndex(obj));
                  }else{
                    trace(obj.fname + ":" + combo2.selectedItem);
                    trace(obj.opera + ":" + combo1.selectedItem);
                    trace(obj.val + ":" + datepick.text);             
                    }
                }   
                  }
            }
            addbutton.enabled = true;
            addopenbracket.enabled = true;
            combo2.enabled = true;
            combo1.enabled = true;
          }

       

            public function addOpenBracket():void{

       

                  var temp:Object = new Object();
                temp.fname = addopenbracket.label
            adhoc.addItem(temp);
            addopenbracket.enabled = false
            addclosebracket.enabled = true
                  if(adhoc.length > 1 && addopenbracket.enabled == false){
                      addbutton.enabled = true
                      }
                   
              }
         
          public function addCloseBracket():void{

       

                var temp:Object = new Object();
                if(adhoc.length > 1){
              temp.fname = addclosebracket.label
              adhoc.addItem(temp);
              addopenbracket.enabled = true
              addclosebracket.enabled = false
                }
            if(adhoc.length > 1 && addclosebracket.enabled == false){
                      addbutton.enabled = true
                      }
          }   
          private function dateChange(date:Date):void{
               
              if (date == null){
                       
                }else{
                      txt.text = date.getDate() + '/' + (date.getMonth()+1).toString() + '/' +
                                date.getFullYear().toString() ;
                }

          } 
          public function saveadhoc(event:Event):void {
           
                  var AdhocRows:String = "";
          var i:int ;
                var selectedType = comboBox.selectedItem;
               
         
                if(adhoc.length == 0){
                Alert.show("Enter The Query");
                }else{
         
          for(i = 0; i < adhoc.length;i++) {
            if(adhoc[i].fname != null){
            AdhocRows = AdhocRows +adhoc[i].fname+" ";
            }
            if(adhoc[i].opera != null){
            AdhocRows = AdhocRows + adhoc[i].opera+" ";
            }
            if(adhoc[i].val != null){
            AdhocRows = AdhocRows + adhoc[i].val+" ";
            }
            if(adhoc[i].cond != null){
            AdhocRows = AdhocRows + adhoc[i].cond+" ";
            }
           
          }
              var parameters:Object = {adhocquery:AdhocRows,FlexActionType:"ADHOCQUERYSUBMIT",adhocType:selectedType};
                //  adhocClick.send(parameters);
                } 
            }             
             
              private function retrieve():void{         
                       
                  datepick.visible = false
                txt.visible = true
                       
              } 
                         
                 
       
         
      ]]>
      </mx:Script>

              <mx:Array id="comp">
                  <mx:String>TYPE</mx:String>
              <mx:String>AUDITRESULT</mx:String>
              <mx:String>CATEGORY</mx:String>
              <mx:String>CHILDRULE</mx:String>
              <mx:String>PARENTRULE</mx:String>
              <mx:String>AUDITGROUP</mx:String>
              <mx:String>LOCATION</mx:String>
              <mx:String>VENDOR</mx:String>
              <mx:String>DEVICECATEGORY</mx:String>
          </mx:Array>
       
         
          <mx:Array id="inven">
        <mx:String>VENDOR</mx:String>
        <mx:String>DEVICETYPE</mx:String>
        <mx:String>SERIES</mx:String>
        <mx:String>MODEL</mx:String>
        <mx:String>SUP/CPU</mx:String>
        <mx:String>CODEVERSION</mx:String>
        <mx:String>IMAGENAME</mx:String>
        <mx:String>DATEDEPLOYED</mx:String>
        <mx:String>LOCATIONNAME</mx:String>
        <mx:String>ADDRESS1</mx:String>
        <mx:String>ADDRESS2</mx:String>
        <mx:String>CITY</mx:String>
        <mx:String>STATE</mx:String>
        <mx:String>COUNTRY</mx:String>
        <mx:String>FLOOR</mx:String>   
        <mx:String>CABINET</mx:String>
        <mx:String>CATEGORYNAME</mx:String>
        <mx:String>DEPARTMENT</mx:String>
        <mx:String>CONTACTNAME</mx:String>
        <mx:String>CONTACTNUMBER</mx:String>
        <mx:String>VERSION</mx:String>
        <mx:String>FILENAME</mx:String>
        <mx:String>DATEUPLOADED</mx:String>
      </mx:Array>

      <mx:Accordion x="13" y="55" width="230" height="492">
      <mx:Form label="AdHoc Query Analyzer"  width="100%"  creationComplete="retrieve()" height="100%" color="#F2F8F9" backgroundColor="#020202">
        <mx:Canvas label="Query" width="204" height="440" backgroundColor="#020202">
        <mx:ComboBox x="66" y="287" width="134"  id="comboBox" dataProvider="[COMPLIANCE , INVENTORY]" change="onChange()" color="#050505">
        </mx:ComboBox>
        <mx:ComboBox x="5" y="344" width="109.25" id="combo1" dataProvider="[=,!=,>,>=,&lt;,&lt;=,LIKE]" color="#010101"></mx:ComboBox>
        <mx:TextInput x="119.25" y="344" width="77.75" id="txt" color="#050505"/>
          <mx:Button x="3" y="401" label="Add" width="59" click="add()" id="addbutton" color="#FFFEFE" fillAlphas="[0.6, 0.4, 0.75, 0.65]" fillColors="[#FFFFFF, #CCCCCC, #EEEEEE, #EEEEEE]" borderColor="#B7BABC" themeColor="#009DFF"/>
        <mx:Button x="66" y="401" label="Delete" width="63.25" click="querydelete()" color="#FFFEFE" fillAlphas="[0.6, 0.4, 0.75, 0.65]" fillColors="[#FFFFFF, #CCCCCC, #EEEEEE, #EEEEEE]" borderColor="#B7BABC" themeColor="#009DFF"/>
        <mx:Button x="2" y="373" label="("  id="addopenbracket" click="addOpenBracket()"  width="45" color="#FFFEFE" fillAlphas="[0.6, 0.4, 0.75, 0.65]" fillColors="[#FFFFFF, #CCCCCC, #EEEEEE, #EEEEEE]" borderColor="#B7BABC" themeColor="#009DFF"/>
        <mx:Button x="51" y="373" label=")" id="addclosebracket" click="addCloseBracket()"  width="45" color="#FFFEFE" fillAlphas="[0.6, 0.4, 0.75, 0.65]" fillColors="[#FFFFFF, #CCCCCC, #EEEEEE, #EEEEEE]" borderColor="#B7BABC" themeColor="#009DFF"/>
        <mx:Button x="134.25" y="401" label="Submit" click="saveadhoc(event);initImage(event)" color="#FFFEFE" fillAlphas="[1.0, 0.69, 0.75, 0.65]" fillColors="[#77B97A, #77B97A, #EEEEEE, #EEEEEE]" borderColor="#77B97A" themeColor="#009DFF"/>
       
        <mx:ComboBox x="66" y="317" width="134" id="combo2" change="onChange1()" dataProvider="{comp}" color="#010101">
        </mx:ComboBox>
        <mx:DateField x="122.25" y="344" width="74.75" initialize="dateChange((event.target).selectedDate)" id="datepick" color="#050505"/>
        <mx:DataGrid x="1" y="1" width="203" height="282" id="AdHoc" dataProvider="{adhoc}" allowMultipleSelection="true" color="#020202">
        <mx:columns>
          <mx:DataGridColumn headerText="Name" dataField="fname" id="fnam"/>
          <mx:DataGridColumn headerText="Operator" dataField="opera" id="ope"/>
          <mx:DataGridColumn headerText="Value" dataField="val" id="valu"/>
          <mx:DataGridColumn headerText="Condition" dataField="cond" id="condt"/>
        </mx:columns>
        </mx:DataGrid>
        <mx:Button x="99" y="373" label="AND" width="52" click="andSubmit()" id="and" color="#FFFEFE" fillAlphas="[0.6, 0.4, 0.75, 0.65]" fillColors="[#FFFFFF, #CCCCCC, #EEEEEE, #EEEEEE]" borderColor="#B7BABC" themeColor="#009DFF"/>
        <mx:Button x="154" y="373" label="OR" width="49" click="orSubmit()" id="or" color="#FFFEFE" fillAlphas="[0.6, 0.4, 0.75, 0.65]" fillColors="[#FFFFFF, #CCCCCC, #EEEEEE, #EEEEEE]" borderColor="#B7BABC" themeColor="#009DFF"/>
        <mx:Label x="7" y="291" text="TYPE" width="59" fontWeight="bold"/>
        <mx:Label x="5" y="319" text="DISPLAY" width="59" fontWeight="bold"/>
          </mx:Canvas>
        </mx:Form>
      </mx:Accordion>

       

      </mx:Application>