A couple of months ago I posted an example that I wrote to show how to filter a Flex DataGrid on the fly. This afternoon a user asked me how to do filtering using date ranges, allowing a date start and end to be specified so as to filter only data that falls within the specified range.
So, here is an updated example. In the interests of simplicity a local ArrayCollection is used. I have added a Date object member named hired (if you were retrieving data from a back-end like ColdFusion then you would likely return a date type which would be converted to an ActionScript Date class so as to be able to easily perform date calculations).
The UI has two DateField controls, startDate and endDate, and a change to either forces a refresh and the filterFunction is applied. The ArrayCollection filterFunction simply checks that the hired date falls between startDate and endDate (allowing null in case no date is selected).
























6 thoughts

  1. Don, you’d still use an ArrayCollection, but instead of hard-coding it, your RemoteObject result handler would populae it with the returned results.
    — Ben

  2. Any help with setting the dateField with todays date? I know you can showDate="True" but it does not select the date. I want the field to be preselected with today’s date.
    Any help would be greatly appreciated.

  3. Sorry, found it. selectedDate="{new Date ()}"
    just leave the () empty.
    Now I have to work on setting a time?
    Anyone know of a datetimeField? 🙂

Leave a Reply to Don Kerr Cancel reply