Thursday, June 5, 2008

displaying error rows in a flex datagrid

As far as I can tell, if you want to allow a user to snag a bunch of data, edit it in a datagrid, and send the edited rows back to a database (regardless of how you're doing so), there is no way to display individual "errors" or "errorRows" in a datagrid. Maybe I'm wrong and my google searching prowess has declined drastically in my old age.

"But Jeremy, shouldn't you just handle those errors up-front?"

Aaaah, yes, that's super. BUT [insert any set of cases where business rules or huge databases might negate your brilliant 'but']. Maybe EACH of your 250+ rows in your datagrid must first check the 10,000 related records to verify something before being submitted. You don't want to get all 250 x 10,000 rows up-front, you just want to check against the ONE that the user is submitting.

On top of that... what are you going to do, just set errorString on the whole component? Wouldn't you rather bring attention to the row or rows causing the error?

The quick fix:

override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number,height:Number,color:uint,dataIndex:int):void

I created a public array in my custom datagrid component. If that array.length > 0 in drawRowBackground, I super.drawRowBackground(s,rowIndex,y,height,color,dataIndex) with a custom color and break out of the function. Oh, and in my case the result object correlates directly to dataIndex, so it's very easy to run a function that pushes error indexes into that array.

write a function to clear that array when need be and you're in like flynn.

(apologies up front... blockquote sucks in this style... I'll go back and write all my code later, or shoot me an email if you have anything for me.)

Tuesday, May 13, 2008

missing enabledChanged metadata in mx.core.UIComponent

I could write a long drawn-out post about how we were creating event listeners today to set the enabled property of some of the button classes in our custom forms at work... blah blah blah.

Bottom line, UIComponent.as is missing this line:
[Event(name="enabledChanged", type="flash.events.Event")]

Give it a shot. Create a component that extends mx.core.Container (or, in our case, extends a custom component that extends Form.as) and create a function bindable to "enabledChanged". It won't work until you add the metadata somewhere.

That is all.

Saturday, May 10, 2008

Flex Builder / Eclipse tip du jour.

It's inevitable. You'll be debugging a Flex application, get an error and will need to look at a class, object, function or the like. Instead of scrolling up and down, or digging through directories, do the following:

Ctrl-click on the 'identifier' in question and you're in like Flynn.

30th time is the charm?

Maybe it's a bad idea to start ANOTHER blog that may fall into the same ol' my-last-post-was-five-months-ago pit. But, what the hell...