[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2429
  • Last Modified:

Flex4 - DataGrid CheckBox (Check Everything)

im using FlashBuilder here,

anyway i have a simple DataGrid, with 2 columns,

one of them has a custom itemrenderer that has a checkbox in it (but i dont use any source for the selected true/false)
and the other column is a basic one ,

 now i am manually adding to the data source a new item that says "All of Them"

so i need that when the user check the checkbox for the "All of Them" it all automatically check all checkboxs for the datagrid.. if the user unselects then it will uncheck all of them but dont know how to access the checkbox in the custom item renderer for every row..

also i need a method that will return all items that are currently with the checkbox marked.. (but i suppose the answer for this one will come from the first aswell)

does anyone have any ideia how to do something like this ?

(is a DataGrid the best choice for something like this or perhaps a list or advdatagrid would be better ? )

Thx

ps. is there a flash builder section ?
0
eguilherme
Asked:
eguilherme
  • 2
1 Solution
 
andreMarianoCommented:
This one is kind fun...
ok... to select or unselect this checkbox, there is an certain field in your dataprovider that sets if it is selected or not, right?
so, when you click in "all of them"
you can create an loop in all your dataprovider setting the field to 1
and when you click "none", you do that same loop setting the field to 0
0
 
eguilhermeAuthor Commented:
yea but thats the thing, i dont have any field on the dataprovider for that checkbox values..

its something like this, my dataprovider is a list of companies.. and i want those in a datagrid where the person can select which or all companies to select and then i will capture the id property of the dataprovider of those who have been selected and send to a webservice

oh well, i guess its easier to create a component to simulate a row and add those in a displaycontainer (group/etc)..
0
 
andreMarianoCommented:
Well, what I suggest is manually adding a field in your dataProvider, something like "SELECTED" = 1 or 0
then in your renderer, you override your set Data method, and then, each time you set your field to 1 or 0, the "set data" method is called...
ex.

public class CheckCellRenderer extends CheckBox
	{
		public var columnName : String;
		
		
		function CheckCellRenderer() {
			super();
			
			addEventListener(MouseEvent.CLICK , change, false, 0, true);
			
			selected = false;
		}

		// Override the set method for the data property.
        override public function set data(value:Object):void {
        	super.data = value;
        	
        	
        	
        	selected = (data[columnName] == "1");
        	
        	
        }
        
		public function change(event:Event){
			if ( selected ) {
				data[columnName] = "1";	
			} else {
				data[columnName] = "0";
			}
		}
	}

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now