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

    How do I delete multiple rows from datagrid?

    xandesign Level 1



      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,



        • 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.*">


                      import mx.collections.ArrayCollection;
                      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:DataGrid dataProvider="{dp}">
                      <mx:DataGridColumn headerText="Column 1" dataField="selected">
                                  <mx:CheckBox selected="{data.selected}" click="data.selected = event.target.selected"/>
                      <mx:DataGridColumn headerText="Column 2" dataField="value"/>
              <mx:Button label="Delete selected" click="handleDelete()"/>