Hi
I also need to show the applicable error message to each of the error cell.
So I use a renderer that extends Label since there's a errorString attribute
for label. However, I keep getting dumped (application freezes) when I add
in errorString. Any idea why?
*
package* {
*import* mx.controls.Label;
*import* mx.controls.listClasses.*;
*public* *class* PriceLabel *extends* Label {
*private* *const* POSITIVE_COLOR:uint = 0x000000; *// Black
*
*private* *const* NEGATIVE_COLOR:uint = 0xFF0000; *// Red
*
*override* *protected* *function* updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):*void* {
*super*.updateDisplayList(unscaledWidth, unscaledHeight);
*/* Set the font color based on the item price. */
*
setStyle(*"color"*, (da...@price <= 0) ? NEGATIVE_COLOR : POSITIVE_COLOR);
this.errorString="err";
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle" creationComplete="setErrorString()"
backgroundColor="white">
<mx:Script>
<![CDATA[
*import* mx.controls.dataGridClasses.DataGridColumn;
*import* mx.utils.ObjectUtil;
*private* *function* price_labelFunc(item:Object,
column:DataGridColumn):String {
*return* currencyFormatter.format(it...@price);
}
*private* *function* price_sortCompareFunc(itemA:Object, itemB:Object):int {
*return* ObjectUtil.numericCompare(ite...@price, ite...@price);
}
*private* *function* setErrorString():*void*{
}
]]>
</mx:Script>
<mx:XML id="itemsXML">
<items>
<item name="Item 1" price="1.32" error="my Error"/>
<item name="Item 2" price="-12.23" error="my Error" />
<item name="Item 3" price="4.96" error="my Error" />
<item name="Item 4" price="-0.94" error="my Error" />
</items>
</mx:XML>
<mx:Style>
.centered {
text-align: center;
}
</mx:Style>
<mx:CurrencyFormatter id="currencyFormatter"
precision="2"
useNegativeSign="false" />
<mx:DataGrid id="dataGrid" dataProvider="{itemsXML.item}">
<mx:columns>
<mx:DataGridColumn dataField="@name"
headerText="Name:"
headerStyleName="centered" />
<mx:DataGridColumn dataField="@price"
headerText="Price:"
textAlign="right"
headerStyleName="centered"
labelFunction="price_labelFunc"
sortCompareFunction="price_sortCompareFunc"
itemRenderer="PriceLabel"
/>
</mx:columns>
</mx:DataGrid>
<mx:Label text="my label" errorString="my error"/>
</mx:Application>
On Wed, May 13, 2009 at 5:57 PM, foobone9 <[email protected]> wrote:
>
>
> I would just create a custom item renderer who examines its own data and if
> it finds something it doesn't like it draws a red bordering using the
> drawing API in updateDisplayList.
>
> --- In [email protected] <flexcoders%40yahoogroups.com>, nhid
> <nhi...@...> wrote:
> >
> > Hi,
> >
> > I am also working on this problem, does anyone has an idea how to draw
> the
> > red border when validation failed on a field in the datagrid?
> >
> > Thanks for any help.
> > Nhi
> >
> > On Fri, May 8, 2009 at 2:50 PM, Ravi Suda <sudaraviku...@...> wrote:
> >
> > >
> > >
> > > John,
> > > I am working on a similar requirement. I want to show the mandatory
> fields
> > > in datagrid as a validation error(red border). Could you provide your
> custom
> > > item renderer that you created.
> > >
> > > Thanks in Advance
> > > Ravi
> > >
> > >
> > > --- In [email protected]
> > > <flexcoders%40yahoogroups.com><flexcoders%
> 40yahoogroups.com>,
> > > "j_lentzz" <jelentz@> wrote:
> > > >
> > > > True. Good idea. I've already coded the method to increment a
> > > > counter to display number of failed items. I'll modify the item
> > > > renderer too and see what appears.
> > > >
> > > > Thanks,
> > > >
> > > > John
> > > > --- In [email protected]
> > > > <flexcoders%40yahoogroups.com><flexcoders%
> 40yahoogroups.com>, "Roman
> > > Protsiuk"
> > > > <roman.protsiuk@> wrote:
> > > > >
> > > > > Then all you need is dataProvider. Validate items held in there.
> And
> > > > change
> > > > > some property of the item that indicates whether it's valid or not.
> > > Then
> > > > > item renderer easily can draw something bad basing on that info.
> > > > >
> > > > > R.
> > > > >
> > > > > On 9/19/07, j_lentzz <jelentz@> wrote:
> > > > > >
> > > > > > I'm doing something like that right now for the individual cells.
> > > > > > I've integrated a validator into the cell object. However, I need
> to
> > > > > > be able to validate the complete datagrid when the save button is
> > > > > > pressed. If the user never moves to a cell, I can't use the
> > > > > > itemEditEnd to validate, I need to move through the data and
> check.
> > > > > > Using the itemEditor.newInstance() and calling my validation
> routine,
> > > > > > I can detect that a validation fails. Now I'm going to try to use
> the
> > > > > > itemRenderer property to indicate the nice red boxes.
> > > > > >
> > > > > > John
> > > > > > --- In [email protected]
> > > > > > <flexcoders%40yahoogroups.com><flexcoders%
> 40yahoogroups.com><flexcoders%
>
> > > 40yahoogroups.com>,
> > > > "Roman
> > > > > > Protsiuk"
> > > > > > <roman.protsiuk@> wrote:
> > > > > > >
> > > > > > > I remember I did it like this:
> > > > > > >
> > > > > > > public class FilesDataGridColumnEditor extends TextInput {
> > > > > > >
> > > > > > > public function SomeDataGridEditor() {
> > > > > > > _validator.source = this;
> > > > > > > _validator.triggerEvent = "change";
> > > > > > > _validator.required = true;
> > > > > > > _validator.property = "text";
> > > > > > > }
> > > > > > >
> > > > > > > private var _validator : Validator = new SomeValidator();
> > > > > > > }
> > > > > > >
> > > > > > > It's not "the best practices", but as far as I remember it
> > > > worked. :)
> > > > > > >
> > > > > > > R.
> > > > > > >
> > > > > > > On 9/18/07, merelypixels <merelypixels@> wrote:
> > > > > > > >
> > > > > > > > seems to me that no mucking about with itemEditors is
> > > necessary...
> > > > > > > > extract the data you need from your dataProvider and then
> > > validate
> > > > > > > > that data directly before sending it on. If you want the
> > > > little red
> > > > > > > > validation things, you should probably validate on a field by
> > > > field
> > > > > > > > basis using the dataGrids itemEditEnd event, validating using
> > > > > > > > dg.itemEditorInstance and doing e.preventDefault() if the
> field
> > > is
> > > > > > > > invalid.
> > > > > > > >
> > > > > > > > Hope that helps!
> > > > > > > > -Pixels
> > > > > > > >
> > > > > > > > --- In
> > > > > > > > [email protected]<flexcoders%40yahoogroups.com><flexcoders%
> 40yahoogroups.com>
> > > > <flexcoders%40yahoogroups.com><flexcoders%40yahoogroups.com>,
> > > > > >
> > > > > > > > "j_lentzz" <jelentz@> wrote:
> > > > > > > > >
> > > > > > > > > Hi,
> > > > > > > > >
> > > > > > > > > I'm now trying to validating the contents of a datagrid and
> > > > I was
> > > > > > > > > wondering if there is an established way to do this. It
> > > > seems like I
> > > > > > > > > would need to get an instance of the itemEditor and somehow
> > > > pass it
> > > > > > > > > the value on that row. Then I would either call a validator
> > > > against
> > > > > > > > > that editor, or call a method contained in the itemEditor
> to
> > > > do the
> > > > > > > > > validation. I can get the itemEditor to do validation when
> > > > the user
> > > > > > > > > is entering data, but I need to be able to do validation on
> > > > all the
> > > > > > > > > entries in the datagrid when the save button is pressed -
> to
> > > > handle
> > > > > > > > > the cases of missing data in required datagrid fields. I've
> > > > found
> > > > > > > > > some examples of how to validate when the user is entering
> > > > data for
> > > > > > > > > that field, but not for validating the complete datagrid.
> Any
> > > > > > help or
> > > > > > > > > ideas would be greatly appreciated.
> > > > > > > > >
> > > > > > > > > John
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > >
> > >
> >
>
>
>