Link to home
Start Free TrialLog in
Avatar of eduardo12fox
eduardo12foxFlag for Brazil

asked on

change color row in datagrid

I have a script that already meets me but would like to send warning signals to my client that something is wrong I was able to change the line color to red I'm working

this can happen in diversar lines and not in sequence. How can I apply this setting?

Below script:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.controls.TextInput;
        import mx.events.DataGridEvent;
        import mx.events.DataGridEventReason;
        
        [Bindable]
        var Acumula:int = 0;

        protected function checkInput(event:DataGridEvent):void
        {
        	
        	
            if (event.reason == DataGridEventReason.NEW_ROW || event.reason == DataGridEventReason.NEW_COLUMN)
            {
                var editor:TextInput = (event.currentTarget as DataGrid).itemEditorInstance as TextInput;
                var text:String = editor.text;
                var myEditor:TextInput =  TextInput(event.currentTarget.itemEditorInstance);

               
                Acumula += int(myEditor.text);
                if(int(Acumula) > int(event.itemRenderer.data.score)) 
                    {                           
                        Acumula = 0;

                        event.preventDefault();

                        Alert.show(text + "ULTRAPASSOU!");

                        return;
                    }
                
            }
        }

    ]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
    <mx:source>
        <mx:Array>
            <mx:Object label="Student A" score="85"/>
            <mx:Object label="Student B" score="48"/>
            <mx:Object label="Student C" score="71"/>
            <mx:Object label="Student D" score="88"/>
            <mx:Object label="Student E" score="24"/>
            <mx:Object label="Student F" score="64"/>
            <mx:Object label="Student G" score="76"/>
            <mx:Object label="Student H" score="76"/>
            <mx:Object label="Student I" score="93"/>
            <mx:Object label="Student J" score="88"/>
            <mx:Object label="Student K" score="48"/>
            <mx:Object label="Student L" score="76"/>
        </mx:Array>
    </mx:source>
</mx:ArrayCollection>
<mx:DataGrid x="10" y="28" dataProvider="{arrColl}" editable="true" itemEditEnd="checkInput(event)">
    <mx:columns>
        <mx:DataGridColumn headerText="Column 1"  dataField="label" editable="false"/>
        <mx:DataGridColumn headerText="Column 2"  dataField="score" editable="false"/>

        <mx:DataGridColumn headerText="Column 3"  editable="true" dataField="col1">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 4"  editable="true" dataField="col2">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 5"  editable="true" dataField="col3">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 6"  editable="true" dataField="col4">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 7"  editable="true" dataField="col5">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

    </mx:columns>
</mx:DataGrid>
	<mx:Label x="164" y="211" text="{Acumula}"/>
</mx:Application>

Open in new window


To test the script for example, the first row is the value defalt go filling 85 columns in the same row until the value is greater than 85 there will be an alert issued.

this time I want to change the color of this line to red.
Avatar of dgofman
dgofman
Flag of United States of America image

eduardo12fox,

I will happy to help you with this problem too, but please can you properly close my previous answers. I will prefer if you will keep your question open but at same time accept some of my posts. Thanks

https://www.experts-exchange.com/questions/28044296/HELP-PLEASE-calc-columns-in-datagrid.html?anchorAnswerId=38931531#a38931531
Avatar of eduardo12fox

ASKER

Ok! My mistake not done correctly, is that I'm still getting used to the site. I hope I have done right this time, and I take this opportunity to thank you again for your help.
Can you explain what do you want? Why you cannot get my previous code and test it.
It's working without Alert
This code below is my script working. What this script does:
He adds columns Column column 3 +  Column 4 + Column 5 + Column 6 + Column7
if that sum is greater than Column 2 it issues a warning.
When this alert is issued I would like to change the color of that whole row to red.

For example if my client fill the column 2 and column 5 and the sum of the two columns is greater than the Column 2 the script issues an alert at this time I would like to paint the red line.

Below is a script running on localhost

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.controls.TextInput;
        import mx.events.DataGridEvent;
        import mx.events.DataGridEventReason;
        
        [Bindable]
        var Acumula:int = 0;

        protected function checkInput(event:DataGridEvent):void
        {
        	
        	
            if (event.reason == DataGridEventReason.NEW_ROW || event.reason == DataGridEventReason.NEW_COLUMN)
            {
                var editor:TextInput = (event.currentTarget as DataGrid).itemEditorInstance as TextInput;
                var text:String = editor.text;
                var myEditor:TextInput =  TextInput(event.currentTarget.itemEditorInstance);

               
                Acumula += int(myEditor.text);
                if(int(Acumula) > int(event.itemRenderer.data.score)) 
                    {                           
                        Acumula = 0;

                        event.preventDefault();

                        Alert.show("ULTRAPASSOU!");

                        return;
                    }
                
            }
        }

    ]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
    <mx:source>
        <mx:Array>
            <mx:Object label="Student A" score="85"/>
            <mx:Object label="Student B" score="48"/>
            <mx:Object label="Student C" score="71"/>
            <mx:Object label="Student D" score="88"/>
            <mx:Object label="Student E" score="24"/>
            <mx:Object label="Student F" score="64"/>
            <mx:Object label="Student G" score="76"/>
            <mx:Object label="Student H" score="76"/>
            <mx:Object label="Student I" score="93"/>
            <mx:Object label="Student J" score="88"/>
            <mx:Object label="Student K" score="48"/>
            <mx:Object label="Student L" score="76"/>
        </mx:Array>
    </mx:source>
</mx:ArrayCollection>
<mx:DataGrid x="10" y="28" dataProvider="{arrColl}" editable="true" itemEditEnd="checkInput(event)">
    <mx:columns>
        <mx:DataGridColumn headerText="Column 1"  dataField="label" editable="false"/>
        <mx:DataGridColumn headerText="Column 2"  dataField="score" editable="false"/>

        <mx:DataGridColumn headerText="Column 3"  editable="true" dataField="col1">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 4"  editable="true" dataField="col2">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 5"  editable="true" dataField="col3">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 6"  editable="true" dataField="col4">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

        <mx:DataGridColumn headerText="Column 7"  editable="true" dataField="col5">
            <mx:itemEditor>
                <mx:Component>
                    <mx:TextInput restrict="0-9"/>
                </mx:Component>
            </mx:itemEditor> 
        </mx:DataGridColumn>

    </mx:columns>
</mx:DataGrid>
	<mx:Label x="164" y="211" text="{Acumula}"/>
</mx:Application>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic!! Really you are a professional.

Greatly improved my script. Thank you friend.