1 Reply Latest reply on Jan 31, 2010 4:20 AM by archemedia

    How do I delete multiple rows from datagrid?

    xandesign

      Hi,

       

      I have a datagrid which has an item renderer on the 1st column which displays a checkbox. I wish to delete all the rows of data from my datagrid which have the checkbox selected.

       

      I'd be very grateful if anyone can anyone help me with this.

       

       

      Thanks in advance,

       

      Xander

        • 1. Re: How do I delete multiple rows from datagrid?
          archemedia Level 4

          Test this:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="vertical" xmlns:components="components.*">

           

              <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      [Bindable]
                      private var dp:ArrayCollection;
                     
                      private function init():void
                      {
                          var sa:Array = [{selected: false, value: "Some value"}, {selected: true, value: "Some other value"}];
                          dp = new ArrayCollection(sa);
                      }
                     
                      private function handleDelete():void
                      {
                          var na:Array = dp.source.filter(function callback(item:*, index:int, array:Array):Boolean
                                  {
                                      return item.selected == false;
                                  });
                          dp.source = na;
                      }
                  ]]>
              </mx:Script>
              <mx:DataGrid dataProvider="{dp}">
                  <mx:columns>
                      <mx:DataGridColumn headerText="Column 1" dataField="selected">
                          <mx:itemRenderer>
                              <mx:Component>
                                  <mx:CheckBox selected="{data.selected}" click="data.selected = event.target.selected"/>
                              </mx:Component>
                          </mx:itemRenderer>
                      </mx:DataGridColumn>
                      <mx:DataGridColumn headerText="Column 2" dataField="value"/>
                  </mx:columns>
              </mx:DataGrid>
              <mx:Button label="Delete selected" click="handleDelete()"/>
          </mx:Application>

           

          Dany