2 Replies Latest reply on Jul 28, 2006 2:29 PM by jb5

    radiobutton data in datagrid

      OK, now that I've actually got a cellRenderer working and am displaying radiobuttons in my datagrid, the question is how do I grab the data from each of the selected radio buttons? I'm not sure of the syntax. Because the radios are sitting in the grid, I can't use the normal "radioGroup.selection.data" to return my values. Any ideas? Thanks in advance!
        • 1. Re: radiobutton data in datagrid
          WebXperience Level 1
          If you gave each radiobutton an instance name you could get the the data using myinstancename.data.
          • 2. Re: radiobutton data in datagrid
            jb5 Level 1
            Thanks. It finally hit me that I could grab radio state (true/false) by looping through the grid, then grab the data from each of the identified true's.

            My data provider is set up like this:
            dataArray.addItem({subhead:"ATTENDANCE", button:{groupName:"", data:"", label:""}});
            dataArray.addItem({subhead:"", button:{groupName:"attend", data:"yes", label:"Will attend"}});
            dataArray.addItem({subhead:"", button:{groupName:"attend", data:"no", label:"Will not attend"}});

            Additional groups go into the dataProvider the same way.

            The cell renderer puts a radio button in the cell using the "button" item and using "radio" as an id. I grab the checked state by using myGrid.getItemAt(n).radio, and the data by using myGrid.getItemAt(n).button.data.

            This is probably a pretty clunky way of setting up name-value pairs but it works:
            1) loop through the datagrid to find the number of unique radio groups--sets up a max number for loops below
            2) loop through the grid to find the location of the buttons that are checked. The location numbers go into an array.
            3) loop through the grid again, using my location numbers to find the radio button data and pair the radio group name with the data

            var dataArrayLn:Number = dataArray.length;
            // calculate number of unique radio groups
            var numberOfGroups:Number = 0;
            for(i=0; i<dataArrayLn; i++) {
            if(eventsGrid.getItemAt(i).button.data == "") {
            // find the grid location of the buttons that are checked
            var buttonCheckedArray:Array = new Array();
            for(i=0; i<dataArrayLn; i++) {
            if(eventsGrid.getItemAt(i).radio) {
            // compare number of checked buttons to number of groups
            // only if all are checked get button data from each of the selected groups
            if(buttonCheckedArray.length != numberOfGroups) {
            Alert.show("Please be sure to make a selection for each item.\n\n", "Alert", Alert.OK);
            } else {
            var buttonDataArray:Array = new Array();
            for(i=0; i<numberOfGroups; i++) {
            var radioGroupName:String = eventsGrid.getItemAt(buttonCheckedArray ).button.groupName;
            var radioData:String = eventsGrid.getItemAt(buttonCheckedArray
            buttonDataArray.push(radioGroupName + "=" + radioData);