1

I have column in data grid containing checkbox. I want to throw an alert when more than 10 check boxes are selected, means on check of 11th checkbox it should throw alert.

I tried below code but it takes lot of time,I am looking for some optimized method, On change handler of checkbox,

protected function checkbox_changeHandler(event:Event):void
{
    data.isUpdated=true;
    data.incpt=chkflag.selected;
    var selectionArray=[];

    for each(var item:Object in outerDocument.adg.dataProvider)
    {
        if(item.incpt)
            selection.push(item);
    }
    if(selectionArray.length > 10)
    {
        for each(var item:Object in outerDocument.adg.dataProvider)
        {
            chkflag.selected=false;
            data.incpt=chkflag.selected;
            outerDocument.adg.dataProvider.refresh();
        }
        Alert.show("Max 10 Items can be selected");
    }
}
  • In your code `selectionArray` is never used, I think it's a typo where you have `selection.push(item)` & `selection.length` you meant it to be `selectionArray` instead, if I am correct. The part where you push the checked items in an array looks okay to me. I don't quite understand the second part where you set all the checked columns to false. Can't we just remove the recently pushed item from the array, display the alert and return from the function? If this a specific requirement then I think the code looks good. – rakemen Apr 11 '16 at 20:17
  • I corrected array name in code above,In second loop i am setting false to disable all checkboxes after 10th item.This code works but as loop runs for each item,if I have 100 records it takes lot of time to display alert – Sharda Deshmukh Apr 12 '16 at 03:53
  • Possible duplicate of [How can I know when a Button in a Flex DataGrid itemRenderer is clicked?](http://stackoverflow.com/questions/1099066/how-can-i-know-when-a-button-in-a-flex-datagrid-itemrenderer-is-clicked) – Brian Apr 12 '16 at 22:03

0 Answers0