<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; refresh()</title>
	<atom:link href="http://blog.flexexamples.com/tag/refresh/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Filtering an MX DataGrid control by date range using Flex</title>
		<link>http://blog.flexexamples.com/2010/02/01/filtering-an-mx-datagrid-control-by-date-range-using-flex/</link>
		<comments>http://blog.flexexamples.com/2010/02/01/filtering-an-mx-datagrid-control-by-date-range-using-flex/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 02:11:22 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[DateField]]></category>
		<category><![CDATA[filterFunction]]></category>
		<category><![CDATA[refresh()]]></category>
		<category><![CDATA[selectableRange]]></category>
		<category><![CDATA[selectedDate]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/?p=2366</guid>
		<description><![CDATA[<p>The following example shows how you can filter an MX DataGrid control in Flex using two MX DateField control&#8217;s and filtering the ArrayCollection data provider.</p> <p></p> &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;!-- http://blog.flexexamples.com/2010/02/01/filtering-an-mx-datagrid-control-by-date-range-using-flex/ --&#62; &#60;mx:Application name=&#34;MX_DataGrid_filter_DateField_test&#34; xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34; layout=&#34;vertical&#34; verticalAlign=&#34;middle&#34; backgroundColor=&#34;white&#34; initialize=&#34;init();&#34;&#62; &#160; &#60;mx:Script&#62; &#60;![CDATA[ protected const MIN_DATE:Date = new Date(2010, 0, 1); protected const MAX_DATE:Date = new [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can filter an MX DataGrid control in Flex using two MX DateField control&#8217;s and filtering the ArrayCollection data provider.</p>
<p><span id="more-2366"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- http://blog.flexexamples.com/2010/02/01/filtering-an-mx-datagrid-control-by-date-range-using-flex/ --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> name=<span style="color: #ff0000;">&quot;MX_DataGrid_filter_DateField_test&quot;</span></span>
<span style="color: #000000;">        xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">        backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span></span>
<span style="color: #000000;">        initialize=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            protected const MIN_DATE:Date = new Date(2010, 0, 1);</span>
<span style="color: #339933;">            protected const MAX_DATE:Date = new Date(2010, 11, 31);</span>
&nbsp;
<span style="color: #339933;">            protected function date_labelFunc(item:Object, col:DataGridColumn):String {</span>
<span style="color: #339933;">                var time:Number = Date.parse(item[col.dataField]);</span>
<span style="color: #339933;">                return new Date(time).toDateString();</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            protected function arrColl_filterFunc(item:Object):Boolean {</span>
<span style="color: #339933;">                var cDate:Number = Date.parse(item.holidayDate);</span>
&nbsp;
<span style="color: #339933;">                if (!sDate || !eDate) {</span>
<span style="color: #339933;">                    return true;</span>
<span style="color: #339933;">                }</span>
&nbsp;
<span style="color: #339933;">                if (sDate.selectedDate &amp;&amp; eDate.selectedDate) {</span>
<span style="color: #339933;">                    return (sDate.selectedDate.time &lt;= cDate) &amp;&amp; (eDate.selectedDate.time &gt;= cDate);</span>
<span style="color: #339933;">                } else if (sDate.selectedDate) {</span>
<span style="color: #339933;">                    return sDate.selectedDate.time &lt;= cDate;</span>
<span style="color: #339933;">                } else if (eDate.selectedDate) {</span>
<span style="color: #339933;">                    return eDate.selectedDate.time &gt;= cDate;</span>
<span style="color: #339933;">                } else {</span>
<span style="color: #339933;">                    return true;</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            protected function init():void {</span>
<span style="color: #339933;">                sDate.selectedDate = MIN_DATE;</span>
<span style="color: #339933;">                sDate.selectableRange = {rangeStart:MIN_DATE, rangeEnd:MAX_DATE};</span>
&nbsp;
<span style="color: #339933;">                eDate.selectedDate = MAX_DATE;</span>
<span style="color: #339933;">                eDate.selectableRange = sDate.selectableRange;</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ArrayCollection</span> id=<span style="color: #ff0000;">&quot;arrColl&quot;</span> filterFunction=<span style="color: #ff0000;">&quot;arrColl_filterFunc&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:source</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Array</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;New Years&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/1/1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Martin Luther King, Jr. Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/1/18&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Groundhog Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/2/2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Chinese New Year&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/2/14&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Valentine's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/2/14&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;President's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/2/15&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Ash Wednesday&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/2/17&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Daylight Saving Time starts&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/3/14&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;St. Patrick's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/3/17&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;First Day of Spring&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/3/20&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;April Fool's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/4/1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Easter&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/4/4&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Administrative Professional's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/4/21&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Earth Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/4/22&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Cinco De Mayo&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/5/5&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Mothers Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/5/9&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Armed Forces Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/5/15&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Memorial Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/5/31&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Flag Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/6/14&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Father's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/6/20&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Summer Begins&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/6/21&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Independence Day/July 4th&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/7/4&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Labor Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/9/6&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Grandparents Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/9/12&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;First Day of Autumn&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/9/23&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Columbus Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/10/11&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;United Nations Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/10/24&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Halloween&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/10/31&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;All Saints' Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/11/1&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Daylight Saving Time Ends&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/11/7&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Veteran's Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/11/11&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Thanksgiving&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/11/25&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Wright Brothers Day&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/12/17&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;First Day Winter&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/12/21&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;Christmas&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/12/25&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> holidayName=<span style="color: #ff0000;">&quot;New Years Eve&quot;</span> holidayDate=<span style="color: #ff0000;">&quot;2010/12/31&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Array</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:source</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ArrayCollection</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ApplicationControlBar</span> dock=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Form</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:FormItem</span> label=<span style="color: #ff0000;">&quot;Start date:&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DateField</span> id=<span style="color: #ff0000;">&quot;sDate&quot;</span> change=<span style="color: #ff0000;">&quot;arrColl.refresh();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:FormItem</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:FormItem</span> label=<span style="color: #ff0000;">&quot;End date:&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DateField</span> id=<span style="color: #ff0000;">&quot;eDate&quot;</span> change=<span style="color: #ff0000;">&quot;arrColl.refresh();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:FormItem</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Form</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ApplicationControlBar</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGrid</span> id=<span style="color: #ff0000;">&quot;dGrid&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{arrColl}&quot;</span> width=<span style="color: #ff0000;">&quot;400&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;holidayName&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;holidayDate&quot;</span> labelFunction=<span style="color: #ff0000;">&quot;date_labelFunc&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:DataGrid</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<div span="googleAdsLeaderboard">
<script type="text/javascript"><!--
google_ad_client = "pub-3325829455487492";
/* 728x90, created 7/15/09 */
google_ad_slot = "6403511741";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
</div>
<p class="information"><a href="http://dl.dropbox.com/u/4509565/FlexExamples_com/MX_DataGrid_filter_DateField_test/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://dl.dropbox.com/u/4509565/FlexExamples_com/MX_DataGrid_filter_DateField_test/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Filtering an MX DataGrid control by date range using Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2010/02/01/filtering-an-mx-datagrid-control-by-date-range-using-flex/',contentID: 'post-2366',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'filterFunction,refresh(),selectableRange,selectedDate,time',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2010/02/01/filtering-an-mx-datagrid-control-by-date-range-using-flex/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Using a Slider to filter items in a DataGrid control in Flex</title>
		<link>http://blog.flexexamples.com/2008/09/12/using-a-slider-to-filter-items-in-a-datagrid-control-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/09/12/using-a-slider-to-filter-items-in-a-datagrid-control-in-flex/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 06:57:41 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[HSlider]]></category>
		<category><![CDATA[filterFunction]]></category>
		<category><![CDATA[refresh()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/12/using-a-slider-to-filter-items-in-a-datagrid-control-in-flex/</guid>
		<description><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/">&#8220;Using a CheckBox to filter items in a DataGrid in Flex&#8221;</a>, we saw how to filter the items in a Flex DataGrid control based on whether the user selected a CheckBox control or not.</p> <p>The following example shows how you can filter items in a Flex DataGrid control using an [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/">&#8220;Using a CheckBox to filter items in a DataGrid in Flex&#8221;</a>, we saw how to filter the items in a Flex DataGrid control based on whether the user selected a CheckBox control or not.</p>
<p>The following example shows how you can filter items in a Flex DataGrid control using an HSlider control, and the ArrayCollection class’s <code>filterFunction</code> property.</p>
<p>Full code after the jump.</p>
<p><span id="more-747"></span></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/09/12/using-a-slider-to-filter-items-in-a-datagrid-control-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.events.SliderEvent;

            private function init():void {
                if (checkBox.selected) {
                    arrColl.filterFunction = sliderFilterFunc;
                    arrColl.refresh();
                }
            }

            private function checkBox_change(evt:Event):void {
                if (checkBox.selected) {
                    arrColl.filterFunction = sliderFilterFunc;
                } else {
                    arrColl.filterFunction = null;
                }
                arrColl.refresh();
            }

            private function slider_change(evt:SliderEvent):void {
                arrColl.refresh();
            }

            private function sliderFilterFunc(item:Object):Boolean {
                var minSlider:uint = slider.values[0];
                var maxSlider:uint = slider.values[1];
                if ((item.value &gt;= minSlider) &#038;&#038;
                            (item.value &lt;= maxSlider)) {
                    return true;
                } else {
                    return false;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="arrColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object label="One" value="100" /&gt;
                &lt;mx:Object label="Two" value="2" /&gt;
                &lt;mx:Object label="Three" value="300" /&gt;
                &lt;mx:Object label="Four" value="40" /&gt;
                &lt;mx:Object label="Five" value="500" /&gt;
                &lt;mx:Object label="Six" value="60" /&gt;
                &lt;mx:Object label="Seven" value="700" /&gt;
                &lt;mx:Object label="Eight" value="800" /&gt;
                &lt;mx:Object label="Nine" value="90" /&gt;
                &lt;mx:Object label="Ten" value="100" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:source&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Form styleName="plain"&gt;
            &lt;mx:FormItem label="filter:"&gt;
                &lt;mx:CheckBox id="checkBox"
                        selected="true"
                        change="checkBox_change(event);" /&gt;
            &lt;/mx:FormItem&gt;
            &lt;mx:FormItem label="values:"&gt;
                &lt;mx:HSlider id="slider"
                        minimum="0"
                        maximum="1000"
                        values="[0,1000]"
                        labels="[0,500,1000]"
                        thumbCount="2"
                        showTrackHighlight="true"
                        snapInterval="1"
                        tickInterval="100"
                        liveDragging="true"
                        change="slider_change(event);" /&gt;
            &lt;/mx:FormItem&gt;
        &lt;/mx:Form&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Panel status="{arrColl.length}/{arrColl.source.length} item(s)"&gt;
        &lt;mx:DataGrid id="dataGrid"
                dataProvider="{arrColl}"
                verticalScrollPolicy="on" /&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using a Slider to filter items in a DataGrid control in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/09/12/using-a-slider-to-filter-items-in-a-datagrid-control-in-flex/',contentID: 'post-747',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'filterFunction,refresh()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/09/12/using-a-slider-to-filter-items-in-a-datagrid-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Determining when an ArrayCollection changes in Flex</title>
		<link>http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/#comments</comments>
		<pubDate>Thu, 15 May 2008 06:32:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[PopUpButton]]></category>
		<category><![CDATA[collectionChange]]></category>
		<category><![CDATA[refresh()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can detect when a Flex ArrayCollection has changed (items added, removed, refreshed) by listening for the collectionChange event.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_collectionChange_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import mx.utils.ObjectUtil; import mx.controls.dataGridClasses.DataGridColumn; import mx.events.CollectionEvent; private function [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can detect when a Flex ArrayCollection has changed (items added, removed, refreshed) by listening for the <code>collectionChange</code> event.</p>
<p>Full code after the jump.</p>
<p><span id="more-629"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_collectionChange_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.ObjectUtil;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.events.CollectionEvent;

            private function arrColl_collectionChange(evt:CollectionEvent):void {
                callLater(addTheItem, [evt]);
            }

            private function arrCollAddItem():void {
                arrColl.addItem({data:new Date()});
            }

            private function addTheItem(evt:Event):void {
                eventsArrColl.addItem(evt);
            }

            private function arrCollRemoveItem():void {
                if (arrColl.length &gt; 0) {
                    arrColl.removeItemAt(0);
                }
            }

            private function dataGridColumn_labelFunc(item:Object, col:DataGridColumn):String {
                return ObjectUtil.toString(item[col.dataField]);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="eventsArrColl" /&gt;
    &lt;mx:ArrayCollection id="arrColl"
            collectionChange="arrColl_collectionChange(event);" /&gt;

    &lt;mx:Model id="columnModel"&gt;
        &lt;columns&gt;
            &lt;bubbles&gt;{bubblesCheckBox.selected}&lt;/bubbles&gt;
            &lt;cancelable&gt;{cancelableCheckBox.selected}&lt;/cancelable&gt;
            &lt;currentTarget&gt;{currentTargetCheckBox.selected}&lt;/currentTarget&gt;
            &lt;eventPhase&gt;{eventPhaseCheckBox.selected}&lt;/eventPhase&gt;
            &lt;items&gt;{itemsCheckBox.selected}&lt;/items&gt;
            &lt;kind&gt;{kindCheckBox.selected}&lt;/kind&gt;
            &lt;location&gt;{locationCheckBox.selected}&lt;/location&gt;
            &lt;oldLocation&gt;{oldLocationCheckBox.selected}&lt;/oldLocation&gt;
            &lt;target&gt;{targetCheckBox.selected}&lt;/target&gt;
            &lt;type&gt;{typeCheckBox.selected}&lt;/type&gt;
        &lt;/columns&gt;
    &lt;/mx:Model&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Add item to ArrayCollection"
                emphasized="true"
                click="arrCollAddItem();" /&gt;
        &lt;mx:Button label="Remove item"
                click="arrCollRemoveItem();" /&gt;
        &lt;mx:Button label="Refresh items"
                click="arrColl.refresh();" /&gt;

        &lt;mx:Spacer width="100%" /&gt;

        &lt;mx:PopUpButton label="Toggle DataGrid columns"
                openAlways="true"&gt;
            &lt;mx:popUp&gt;
                &lt;mx:Form styleName="plain"
                        backgroundColor="white"&gt;
                    &lt;mx:FormItem label="bubbles:"&gt;
                        &lt;mx:CheckBox id="bubblesCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="cancelable:"&gt;
                        &lt;mx:CheckBox id="cancelableCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="currentTarget:"&gt;
                        &lt;mx:CheckBox id="currentTargetCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="eventPhase:"&gt;
                        &lt;mx:CheckBox id="eventPhaseCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="items:"&gt;
                        &lt;mx:CheckBox id="itemsCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="kind:"&gt;
                        &lt;mx:CheckBox id="kindCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="location:"&gt;
                        &lt;mx:CheckBox id="locationCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="oldLocation:"&gt;
                        &lt;mx:CheckBox id="oldLocationCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="target:"&gt;
                        &lt;mx:CheckBox id="targetCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                    &lt;mx:FormItem label="type:"&gt;
                        &lt;mx:CheckBox id="typeCheckBox"
                                selected="true" /&gt;
                    &lt;/mx:FormItem&gt;
                &lt;/mx:Form&gt;
            &lt;/mx:popUp&gt;
        &lt;/mx:PopUpButton&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:VDividedBox width="100%" height="100%"&gt;
        &lt;mx:List id="list"
                dataProvider="{arrColl}"
                labelField="data"
                width="50%"
                rowCount="5" /&gt;
        &lt;mx:DataGrid id="dataGrid"
                dataProvider="{eventsArrColl}"
                itemRenderer="mx.controls.Label"
                width="100%"
                height="100%"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="bubbles"
                        visible="{columnModel.bubbles}" /&gt;
                &lt;mx:DataGridColumn dataField="cancelable"
                        visible="{columnModel.cancelable}" /&gt;
                &lt;mx:DataGridColumn dataField="currentTarget"
                        visible="{columnModel.currentTarget}" /&gt;
                &lt;mx:DataGridColumn dataField="eventPhase"
                        visible="{columnModel.eventPhase}" /&gt;
                &lt;mx:DataGridColumn dataField="items"
                        labelFunction="dataGridColumn_labelFunc"
                        visible="{columnModel.items}" /&gt;
                &lt;mx:DataGridColumn dataField="kind"
                        visible="{columnModel.kind}" /&gt;
                &lt;mx:DataGridColumn dataField="location"
                        visible="{columnModel.location}" /&gt;
                &lt;mx:DataGridColumn dataField="oldLocation"
                        visible="{columnModel.oldLocation}" /&gt;
                &lt;mx:DataGridColumn dataField="target"
                        visible="{columnModel.target}" /&gt;
                &lt;mx:DataGridColumn dataField="type"
                        visible="{columnModel.type}" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
    &lt;/mx:VDividedBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_collectionChange_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_collectionChange_test/bin/main.html" width="100%" height="500"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Determining when an ArrayCollection changes in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/',contentID: 'post-629',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'collectionChange,refresh()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/05/14/determining-when-an-arraycollection-changes-in-flex/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Resetting a sort on a DataGrid control in Flex</title>
		<link>http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 06:51:23 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[refresh()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can reset a sort on a Flex DataGrid control by setting the ArrayCollection data provider&#8217;s sort property to null and refreshing the array collection using the refresh() method.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test_2/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can reset a sort on a Flex DataGrid control by setting the ArrayCollection data provider&#8217;s sort property to <code>null</code> and refreshing the array collection using the <code>refresh()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-589"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test_2/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.Sort;

            private function refreshSort():Boolean {
                arrColl.sort = null;
                return arrColl.refresh();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="arrColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object en="One" fr="Un" es="Uno" /&gt;
                &lt;mx:Object en="Two" fr="Deux" es="Dos" /&gt;
                &lt;mx:Object en="Three" fr="Trois" es="Tres" /&gt;
                &lt;mx:Object en="Four" fr="Quatre" es="Cuatro" /&gt;
                &lt;mx:Object en="Five" fr="Cinq" es="Cinco" /&gt;
                &lt;mx:Object en="Six" fr="Six" es="Seis" /&gt;
                &lt;mx:Object en="Seven" fr="Sept" es="Siete" /&gt;
                &lt;mx:Object en="Eight" fr="Huit" es="Ocho" /&gt;
                &lt;mx:Object en="Nine" fr="Neuf" es="Nueve" /&gt;
                &lt;mx:Object en="Ten" fr="Dix" es="Diez" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:source&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Reset sort"
                click="refreshSort();" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            rowCount="6"
            verticalScrollPolicy="on"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="en"
                    headerText="English:" /&gt;
            &lt;mx:DataGridColumn dataField="fr"
                    headerText="French:" /&gt;
            &lt;mx:DataGridColumn dataField="es"
                    headerText="Spanish:" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test_2/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test_2/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Resetting a sort on a DataGrid control in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/',contentID: 'post-589',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'refresh()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/04/08/resetting-a-sort-on-a-datagrid-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using a CheckBox to filter items in a DataGrid in Flex</title>
		<link>http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 02:42:18 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[filterFunction]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[refresh()]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can filter items in a Flex DataGrid using a CheckBox control, and the ArrayCollection class&#8217;s filterFunction property.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_filterFunction_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import mx.controls.dataGridClasses.DataGridColumn; private function toggleFilter():void { if (checkBox.selected) { [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can filter items in a Flex DataGrid using a CheckBox control, and the ArrayCollection class&#8217;s <code>filterFunction</code> property.</p>
<p>Full code after the jump.</p>
<p><span id="more-560"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_filterFunction_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;

            private function toggleFilter():void {
                if (checkBox.selected) {
                    arrColl.filterFunction = processFilter;
                } else {
                    arrColl.filterFunction = null;
                }
                arrColl.refresh();
            }

            private function processFilter(item:Object):Boolean {
                return parseFloat(item.value) == 0;
            }

            private function value_labelFunc(item:Object, col:DataGridColumn):String {
                return item[col.dataField].toFixed(2);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="arrColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object name="ColdFusion" value="0.00" /&gt;
                &lt;mx:Object name="Dreamweaver" value="0.12" /&gt;
                &lt;mx:Object name="Fireworks" value="1.01" /&gt;
                &lt;mx:Object name="Flash" value="0" /&gt;
                &lt;mx:Object name="Flash Player" value="-0.00" /&gt;
                &lt;mx:Object name="Flex" value="0.00" /&gt;
                &lt;mx:Object name="Illustrator" value="2.92" /&gt;
                &lt;mx:Object name="Lightroom" value="0.32" /&gt;
                &lt;mx:Object name="Photoshop" value="0.06" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:source&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:Panel status="{arrColl.length}/{arrColl.source.length} item(s)"&gt;
        &lt;mx:DataGrid id="dataGrid"
                dataProvider="{arrColl}"
                verticalScrollPolicy="on"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="name" /&gt;
                &lt;mx:DataGridColumn dataField="value"
                        labelFunction="value_labelFunc" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:CheckBox id="checkBox"
                    label="Filter DataGrid"
                    click="toggleFilter();" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_filterFunction_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_filterFunction_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using a CheckBox to filter items in a DataGrid in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/',contentID: 'post-560',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'filterFunction,length,refresh(),source',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Sorting an ArrayCollection using the SortField and Sort classes</title>
		<link>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/</link>
		<comments>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/#comments</comments>
		<pubDate>Sun, 05 Aug 2007 15:18:48 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[SortField]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[refresh()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/</guid>
		<description><![CDATA[<p>Sometimes in life you just need data to be sorted. Whether its a case insensitive sort (for names) or a numeric sort (for, uh, numbers), you just want things sorted in a particular order.</p> <p>This example demonstrates how you can take a bunch of random numbers in an ArrayCollection and sort them numerically in ascending [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes in life you just need data to be sorted. Whether its a case insensitive sort (for names) or a numeric sort (for, uh, numbers), you just want things sorted in a particular order.</p>
<p>This example demonstrates how you can take a bunch of random numbers in an ArrayCollection and sort them numerically in ascending order.</p>
<p><span id="more-56"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test/bin/srcview/ArrayCollection_sort_test.zip">Download source (ZIP, 1K)</a> | <a href="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test/main.mxml">View MXML</a></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.collections.SortField;</span>
<span style="color: #339933;">            import mx.collections.Sort;</span>
<span style="color: #339933;">            import mx.collections.ArrayCollection;</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            private var arrColl:ArrayCollection;</span>
&nbsp;
<span style="color: #339933;">            /** This method gets called by the main mx:Application tag and initializes/populates the ArrayCollection object with a bunch of random numbers. */</span>
<span style="color: #339933;">            private function init():void {</span>
<span style="color: #339933;">                var i:int;</span>
&nbsp;
<span style="color: #339933;">                /* Initialize and populate the ArrayCollection object. */</span>
<span style="color: #339933;">                arrColl = new ArrayCollection();</span>
<span style="color: #339933;">                for (i = 0; i &lt; 20; i++) {</span>
<span style="color: #339933;">                    arrColl.addItem({data:getRandomNumber().toFixed(4)});</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            /** This method returns a random floating-point number between 0 and 10000. */</span>
<span style="color: #339933;">            private function getRandomNumber():Number {</span>
<span style="color: #339933;">                return Math.random() * 10000;</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            /** This method gets called by the Button control's click handler and creates a new SortField and Sort object which are used to sort the ArrayCollection. */</span>
<span style="color: #339933;">            private function button_click():void {</span>
<span style="color: #339933;">                /* Create the SortField object for the &quot;data&quot; field in the ArrayCollection object, and make sure we do a numeric sort. */</span>
<span style="color: #339933;">                var dataSortField:SortField = new SortField();</span>
<span style="color: #339933;">                dataSortField.name = &quot;data&quot;;</span>
<span style="color: #339933;">                dataSortField.numeric = true;</span>
&nbsp;
<span style="color: #339933;">                /* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */</span>
<span style="color: #339933;">                var numericDataSort:Sort = new Sort();</span>
<span style="color: #339933;">                numericDataSort.fields = [dataSortField];</span>
&nbsp;
<span style="color: #339933;">                /* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */</span>
<span style="color: #339933;">                arrColl.sort = numericDataSort;</span>
<span style="color: #339933;">                arrColl.refresh();</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:List</span> id=<span style="color: #ff0000;">&quot;list&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{arrColl}&quot;</span> textAlign=<span style="color: #ff0000;">&quot;right&quot;</span> labelField=<span style="color: #ff0000;">&quot;data&quot;</span> width=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;button&quot;</span> label=<span style="color: #ff0000;">&quot;sort items&quot;</span> click=<span style="color: #ff0000;">&quot;button_click()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p class="information">View source is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ArrayCollection_sort_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Sorting an ArrayCollection using the SortField and Sort classes on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/',contentID: 'post-56',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'fields,refresh()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
	</channel>
</rss>

