3 Replies Latest reply on Aug 2, 2007 3:33 PM by ntsiii

    DataGrid  - Select multiple items by checkboxes

    Misenko Level 1
      I want to select multiple items in the datagrid row but not by holding CTRL button a click. Therefore, I have checkboxes on each row (itemRenderer). Now I would like click on some checkbox, let's say on row 2 and row 2 is highlited. Then I want click on row 5, and rows 2 and 5 are highligted ( selected). If I click again on check box 5, row is unselected. Can you advise me ??

      Thanks
        • 1. Re: DataGrid  - Select multiple items by checkboxes
          france2003
          I just ran across this issue this week, too. I was trying to create a datagrid of items in which the user could select one or many of and when they click submit, the selected items would be removed from the list. After taking a few different approaches, this is the one I ended up with...

          First, I added a bit column to the ArrayCollection that is populating the datagrid. I initially set the bit column to 0 for all items. The bit column will represent whether or not the checkbox is checked.

          Then, inside the checkbox itemRenderer, I have a click event that calls a function in the parentDocument and passes the value of the checkbox [checkbox.selected]. The function inside the parentDocument updates the value of the bit column/property in the ArrayCollection. When the user submits the form, I loop over the ArrayCollection and handle only those in which the bit column/property has been changed to 1.

          One other thing, I had to add this to the itemRenderer so that there would not be any issues when the user scrolled the list...

          // this override is essential for preventing random (un)checking when your DataGrid is scrolled
          override public function set data(value:Object):void
          {
          // not sure of the details on when or why, but sometimes this method is passed a null value
          if(value != null)
          {
          super.data = value;
          // set itemRenderer's state based on data value
          markPaid.selected = value.MarkForPayment;
          }
          }

          Hope that helps...
          • 2. Re: DataGrid  - Select multiple items by checkboxes
            Misenko Level 1
            Thanks for answer, but could you please post here the particular functions which have you talked about??? And what is the bit column in array collection? I have an array column collection with particular colums, where have I add this property? Thanks
            • 3. Re: DataGrid  - Select multiple items by checkboxes
              ntsiii Level 3
              A dataProvider for a list-based component, like dataGrid, is a collection of "item" objects. These can be of several datatypes, including xml, Object, and custom class.

              The "bit column" is simply some property on the item object that can store the value of the checkbox selected property.

              Tracy