Interchange

Tag: Date

Flex DataGrid Date itemEditor

by hbomb on Mar.15, 2009, under Flex

A date editor is a terrible thing to waste

A date editor is a terrible thing to waste

I’ve been working with DataGrids for some time now, but have never had the… pleasure(?) of dealing with editing a Date object within a data grid. I generally feel it’s more appropriate to edit a data record in a customized form, but sometimes it just makes sense to edit it right then and there. This time I ran into a situation where I had to deal with editing a date within the dataGrid. Adding the DateChooser as an itemEditor was simple, but getting it back from a text string to a date object after editing was finished was a bit of a pain. However, once you extended a DateField, it becomes much easier. The heavy lifting is done below.


package com.binaryexposure.editors{
	import mx.controls.DateField;
	import mx.controls.listClasses.IListItemRenderer;

	public class DateEditor extends DateField implements IListItemRenderer{
		public function DateEditor(){
			super();
		}
		override public function set data(value:Object):void{
			if(listData){
				var date:Date;
				if(incomingVal is String){
					date = new Date(Date.parse(data as String));
					super.data = date;
				}
				else if (incomingVal is Date){
					super.data = incominVal as Date;
				}
			}
		}
	}
}

At any rate, I found it to be extremely easy and an interesting take on the processing of the data post-edit.

Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...