Count the number of times an item has been clicked.

In the data grid if an item is clicked I would like to know.  Example: if i click the third item in the data grid 2 times I would like a field where the selected item is to count those clicks, that field would display 2.  If i click the first item in the data grid 4 times I would like a field where the selected item is to count those clicks, that field would display 4.

Is this possible?
aduvallAsked:
Who is Participating?
 
MaartenHensenCommented:
Am only started flex ( 4 in my case a few days ago) but I used " itemClick="rowclick(event)" " as a datagrid attribute for something similar I guess.

You then create that function:

private function rowclick(event:ListEvent):void {
      item = event.rowIndex;
}

Now you only need to use that function to populate an array and you can again output that array.

At least thats the way, I as a beginner, would do it.
0
 
IqAndreasCommented:
How are you creating and populating this data grid. It would be easier if you upload a sample project that I could open and mess around with.

Will you be changing and sorting the items in the grid, or will they remain the same throughout? This may have an impact on the resulting code.

However, if you do as MaartenHensen described and set the "itemClick" property, change the rowclick function to something like the attached code.


Just ask if you have any questions,
Andreas
private var timesClicked:Array = new Array();
private function rowclick(event:ListEvent):void {
    timesClicked[event.rowIndex] = int(timesClicked[event.rowIndex]) + 1;
}


//Retrieve the value like this:
trace(timesClicked[<row number>]);

Open in new window

0
 
aduvallAuthor Commented:
 Hello, the array collection below does not change and supplies data to the dg below.  I just need to know how many times an item has been clicked and have it displayed in the Quant column.

<mx:ArrayCollection id="myData">
        <mx:source>
            <mx:Array>
                <mx:Object item="1" descrip="test" quant="1"  price="140" isSelected = "false"/>
               
                <mx:Object item="2" descrip="test a" quant="1"  price="140" isSelected = "false"/>
               
               
                <mx:Object item="3" descrip="test b" quant="1"  price="285" isSelected = "false"/>
             
                <mx:Object item="4" descrip="test c" quant="1"  price="140" isSelected = "false"/>
               
            </mx:Array>
        </mx:source>
    </mx:ArrayCollection>

      <mx:DataGrid x="28" y="26" id="grid" itemEditEnd="rowclick(event);" dataProvider="{myData}" alpha="1.0" borderStyle="none" alternatingItemColors="[#FFFFFF, #FFFFFF]" borderColor="#FFFFFF" color="#000000" click="upGrade();" width="753" themeColor="#82C7DB">
            <mx:columns>
                  <mx:DataGridColumn headerText="Item#" dataField="item"/>
                  <mx:DataGridColumn headerText="Description" dataField="descrip"/>
                  <mx:DataGridColumn headerText="Price" dataField="price"/>
                  <mx:DataGridColumn headerText="Quant" }"/>

0
 
IqAndreasCommented:
There seems to be missing a chunk of code from that.

Do you think you could upload the entire project as a ZIP file?

That makes it a lot easier to help you out. :)
0
 
aduvallAuthor Commented:
Thank You!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.