<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Dynamically adding new columns to a DataGrid control in Flex</title>
	<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Thu, 08 Jan 2009 13:42:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: billp</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-16574</link>
		<author>billp</author>
		<pubDate>Tue, 04 Nov 2008 23:14:00 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-16574</guid>
		<description>Might have answered my own question...I am sure you have a better solution bur I found this and it worked for me...

http://blog.classsoftware.com/index.cfm/2007/6/17/Flex-Datagrid-Visibility-Bug</description>
		<content:encoded><![CDATA[<p>Might have answered my own question&#8230;I am sure you have a better solution bur I found this and it worked for me&#8230;</p>
<p><a href="http://blog.classsoftware.com/index.cfm/2007/6/17/Flex-Datagrid-Visibility-Bug" rel="nofollow">http://blog.classsoftware.com/index.cfm/2007/6/17/Flex-Datagrid-Visibility-Bug</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: billp</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-16573</link>
		<author>billp</author>
		<pubDate>Tue, 04 Nov 2008 22:40:40 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-16573</guid>
		<description>The code for the checkbox works well but when I use send a new request out using httpservice call to PHP all the columns appear again....Even if none are selected on the checkboxes...Is there something I am missing?</description>
		<content:encoded><![CDATA[<p>The code for the checkbox works well but when I use send a new request out using httpservice call to PHP all the columns appear again&#8230;.Even if none are selected on the checkboxes&#8230;Is there something I am missing?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15967</link>
		<author>Kirk</author>
		<pubDate>Thu, 02 Oct 2008 05:57:02 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15967</guid>
		<description>Thank you for the quick response.  That is a much more elegant solution.</description>
		<content:encoded><![CDATA[<p>Thank you for the quick response.  That is a much more elegant solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15960</link>
		<author>peterd</author>
		<pubDate>Wed, 01 Oct 2008 07:18:49 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15960</guid>
		<description>Kirk,

I'd probably just try and toggle the &lt;code&gt;visible&lt;/code&gt; property on the DataGridColumn. Something like this:
&lt;pre class="code"&gt;
&#60;?xml version="1.0" encoding="utf-8"?&#62;
&#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&#62;

    &#60;mx:ArrayCollection id="arrColl"&#62;
        &#60;mx:source&#62;
            &#60;mx:Array&#62;
                &#60;mx:Object col1="A.1" col2="A.2" col3="A.3" col4="A.4"/&#62;
                &#60;mx:Object col1="B.1" col2="B.2" col3="B.3" col4="B.4"/&#62;
                &#60;mx:Object col1="C.1" col2="C.2" col3="C.3" col4="C.4"/&#62;
                &#60;mx:Object col1="D.1" col2="D.2" col3="D.3" col4="D.4"/&#62;
                &#60;mx:Object col1="E.1" col2="E.2" col3="E.3" col4="E.4"/&#62;
                &#60;mx:Object col1="F.1" col2="F.2" col3="F.3" col4="F.4"/&#62;
            &#60;/mx:Array&#62;
        &#60;/mx:source&#62;
    &#60;/mx:ArrayCollection&#62;

    &#60;mx:ApplicationControlBar dock="true"&#62;
        &#60;mx:CheckBox id="checkBox1" label="Toggle col1" selected="true" /&#62;
        &#60;mx:CheckBox id="checkBox2" label="Toggle col2" selected="true" /&#62;
        &#60;mx:CheckBox id="checkBox3" label="Toggle col3" selected="true" /&#62;
    &#60;/mx:ApplicationControlBar&#62;

    &#60;mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            width="400"
            rowCount="5"&#62;
        &#60;mx:columns&#62;
            &#60;mx:DataGridColumn dataField="col1"
                    visible="{checkBox1.selected}" /&#62;
            &#60;mx:DataGridColumn dataField="col2"
                    visible="{checkBox2.selected}" /&#62;
            &#60;mx:DataGridColumn dataField="col3"
                    visible="{checkBox3.selected}" /&#62;
        &#60;/mx:columns&#62;
    &#60;/mx:DataGrid&#62;

&#60;/mx:Application&#62;
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>Kirk,</p>
<p>I&#8217;d probably just try and toggle the <code>visible</code> property on the DataGridColumn. Something like this:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:ArrayCollection id="arrColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object col1="A.1" col2="A.2" col3="A.3" col4="A.4"/&gt;
                &lt;mx:Object col1="B.1" col2="B.2" col3="B.3" col4="B.4"/&gt;
                &lt;mx:Object col1="C.1" col2="C.2" col3="C.3" col4="C.4"/&gt;
                &lt;mx:Object col1="D.1" col2="D.2" col3="D.3" col4="D.4"/&gt;
                &lt;mx:Object col1="E.1" col2="E.2" col3="E.3" col4="E.4"/&gt;
                &lt;mx:Object col1="F.1" col2="F.2" col3="F.3" col4="F.4"/&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:source&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:CheckBox id="checkBox1" label="Toggle col1" selected="true" /&gt;
        &lt;mx:CheckBox id="checkBox2" label="Toggle col2" selected="true" /&gt;
        &lt;mx:CheckBox id="checkBox3" label="Toggle col3" selected="true" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}"
            width="400"
            rowCount="5"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="col1"
                    visible="{checkBox1.selected}" /&gt;
            &lt;mx:DataGridColumn dataField="col2"
                    visible="{checkBox2.selected}" /&gt;
            &lt;mx:DataGridColumn dataField="col3"
                    visible="{checkBox3.selected}" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15959</link>
		<author>Kirk</author>
		<pubDate>Wed, 01 Oct 2008 05:55:11 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15959</guid>
		<description>I am using this example with a checkbox instead of a button.

How does the code change to delete the column when unchecked, instead of adding a duplicate column?</description>
		<content:encoded><![CDATA[<p>I am using this example with a checkbox instead of a button.</p>
<p>How does the code change to delete the column when unchecked, instead of adding a duplicate column?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GT</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15021</link>
		<author>GT</author>
		<pubDate>Fri, 29 Aug 2008 12:50:07 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-15021</guid>
		<description>Both the tutorial in toto, and the comment that helped Vincent Lesieux, were tremendously useful to me. I had decided that I would like to be able to change the entire contents of a DataGrid (from price-related data to valuation-related data) on the client side as a selection, as part of a Watchlist/Portfolio manager app. The number of columns would change as a result.

Thanks to this tute and others on this site, I can now offer a customised list of columns, fetch the data from mySQL, and populate the new colums... or replace the entire DataGrid in one fell swoop using pre-defined sets of columns.

I've been meaning for a month to write a thank-you for this, and for other insightful entries here: my only excuse for not having done so until now is that I have been absolutely drowning in tasks that had to be done in order to finish the apps.

Thanks muchly,


GT</description>
		<content:encoded><![CDATA[<p>Both the tutorial in toto, and the comment that helped Vincent Lesieux, were tremendously useful to me. I had decided that I would like to be able to change the entire contents of a DataGrid (from price-related data to valuation-related data) on the client side as a selection, as part of a Watchlist/Portfolio manager app. The number of columns would change as a result.</p>
<p>Thanks to this tute and others on this site, I can now offer a customised list of columns, fetch the data from mySQL, and populate the new colums&#8230; or replace the entire DataGrid in one fell swoop using pre-defined sets of columns.</p>
<p>I&#8217;ve been meaning for a month to write a thank-you for this, and for other insightful entries here: my only excuse for not having done so until now is that I have been absolutely drowning in tasks that had to be done in order to finish the apps.</p>
<p>Thanks muchly,</p>
<p>GT</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PJW</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-13458</link>
		<author>PJW</author>
		<pubDate>Mon, 16 Jun 2008 19:59:55 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-13458</guid>
		<description>Hi,
Several weeks ago I was wrestling with DataGrid renderers.

The above posts helped... as well as other sources I googled up. Without going into the specifics of my own solution (needed to be entirely ActionScript, i.e. no MXML) here are some posts I found useful (hopefully this blog doesn't treat this like a spam post). Hopefully these help out others who face similar challenges.

http://philflash.inway.fr/flex/dgRendererSimple/dgRendererSimple.html

…a couple more (WordPress doesn’t like too many URLs in posts):
http://philflash.inway.fr/flex/dgRendererSimple/srcview/index.html
http://www.mail-archive.com/flexcoders@yahoogroups.com/msg85212.html
http://www.adobe.com/devnet/flash/articles/detecting_datagrid_edits.html

Yet some more:
http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/
http://www.actionscript.org/forums/showthread.php3?t=163781
http://www.returnundefined.com/2006/10/item-renderers-in-datagrids-a-primer-for-predictable-behavior

…and the last (Moderator: you might want to combine these posts, if you think your readers will find useful. Thanks.)
http://bugs.adobe.com/jira/browse/FLEXDOCS-142
http://blog.flexmonkeypatches.com/tag/itemrenderer/
http://www.nabble.com/item-renderers-in-a-datagrid-with-dynamically-created-columns-td16567760.html
http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html

http://blogs.adobe.com/aharui/MultilineHTML.zip</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Several weeks ago I was wrestling with DataGrid renderers.</p>
<p>The above posts helped&#8230; as well as other sources I googled up. Without going into the specifics of my own solution (needed to be entirely ActionScript, i.e. no MXML) here are some posts I found useful (hopefully this blog doesn&#8217;t treat this like a spam post). Hopefully these help out others who face similar challenges.</p>
<p><a href="http://philflash.inway.fr/flex/dgRendererSimple/dgRendererSimple.html" rel="nofollow">http://philflash.inway.fr/flex/dgRendererSimple/dgRendererSimple.html</a></p>
<p>…a couple more (WordPress doesn’t like too many URLs in posts):<br />
<a href="http://philflash.inway.fr/flex/dgRendererSimple/srcview/index.html" rel="nofollow">http://philflash.inway.fr/flex/dgRendererSimple/srcview/index.html</a><br />
<a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg85212.html" rel="nofollow">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg85212.html</a><br />
<a href="http://www.adobe.com/devnet/flash/articles/detecting_datagrid_edits.html" rel="nofollow">http://www.adobe.com/devnet/flash/articles/detecting_datagrid_edits.html</a></p>
<p>Yet some more:<br />
<a href="http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/" rel="nofollow">http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/</a><br />
<a href="http://www.actionscript.org/forums/showthread.php3?t=163781" rel="nofollow">http://www.actionscript.org/forums/showthread.php3?t=163781</a><br />
<a href="http://www.returnundefined.com/2006/10/item-renderers-in-datagrids-a-primer-for-predictable-behavior" rel="nofollow">http://www.returnundefined.com/2006/10/item-renderers-in-datagrids-a-primer-for-predictable-behavior</a></p>
<p>…and the last (Moderator: you might want to combine these posts, if you think your readers will find useful. Thanks.)<br />
<a href="http://bugs.adobe.com/jira/browse/FLEXDOCS-142" rel="nofollow">http://bugs.adobe.com/jira/browse/FLEXDOCS-142</a><br />
<a href="http://blog.flexmonkeypatches.com/tag/itemrenderer/" rel="nofollow">http://blog.flexmonkeypatches.com/tag/itemrenderer/</a><br />
<a href="http://www.nabble.com/item-renderers-in-a-datagrid-with-dynamically-created-columns-td16567760.html" rel="nofollow">http://www.nabble.com/item-renderers-in-a-datagrid-with-dynamically-created-columns-td16567760.html</a><br />
<a href="http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html" rel="nofollow">http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html</a></p>
<p><a href="http://blogs.adobe.com/aharui/MultilineHTML.zip" rel="nofollow">http://blogs.adobe.com/aharui/MultilineHTML.zip</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-12200</link>
		<author>Greg</author>
		<pubDate>Tue, 22 Apr 2008 08:16:14 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-12200</guid>
		<description>Peter, you rock!
Modified it a bit, needed it to set the datafield, not the headertext.

Here's my code:

&lt;pre class="code"&gt;
private function addDataGridColumn(dataField:String):void {
    var dgc:DataGridColumn = new DataGridColumn(dataField);
    dgc.visible = false;
    var cols:Array = peopleMainDB.columns;
    cols.push(dgc);
    peopleMainDB.columns = cols;
    trace("Number of columns:" + peopleMainDB.columns.length)
}

private function init():void {
    var x:String = "icon " + (peopleMainDB.columns.length + 1);
    addDataGridColumn(x);
}
&lt;/pre&gt;

Thanks again, wish I had you around for all of my flex problems.</description>
		<content:encoded><![CDATA[<p>Peter, you rock!<br />
Modified it a bit, needed it to set the datafield, not the headertext.</p>
<p>Here&#8217;s my code:</p>
<pre class="code">
private function addDataGridColumn(dataField:String):void {
    var dgc:DataGridColumn = new DataGridColumn(dataField);
    dgc.visible = false;
    var cols:Array = peopleMainDB.columns;
    cols.push(dgc);
    peopleMainDB.columns = cols;
    trace("Number of columns:" + peopleMainDB.columns.length)
}

private function init():void {
    var x:String = "icon " + (peopleMainDB.columns.length + 1);
    addDataGridColumn(x);
}
</pre>
<p>Thanks again, wish I had you around for all of my flex problems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-12198</link>
		<author>peterd</author>
		<pubDate>Tue, 22 Apr 2008 07:06:24 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-12198</guid>
		<description>Greg,

Does this work for you?
&lt;pre class="code"&gt;
private function addDataGridColumn(dataField:String):void {
    var dgc:DataGridColumn = new DataGridColumn(dataField);
    dgc.visible = false;
    dgc.headerText = "col " + (dataGrid.columns.length + 1);
    var cols:Array = dataGrid.columns;
    cols.push(dgc);
    dataGrid.columns = cols;
}
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>Greg,</p>
<p>Does this work for you?</p>
<pre class="code">
private function addDataGridColumn(dataField:String):void {
    var dgc:DataGridColumn = new DataGridColumn(dataField);
    dgc.visible = false;
    dgc.headerText = "col " + (dataGrid.columns.length + 1);
    var cols:Array = dataGrid.columns;
    cols.push(dgc);
    dataGrid.columns = cols;
}
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg</title>
		<link>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-12197</link>
		<author>Greg</author>
		<pubDate>Tue, 22 Apr 2008 06:55:31 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-control-in-flex/#comment-12197</guid>
		<description>Awesome, definitely works. Two questions.

1st. can I dynamically label these using .columnCount?

2nd. can I make the new columns invisible on creation?

Appreciate any help.

-G</description>
		<content:encoded><![CDATA[<p>Awesome, definitely works. Two questions.</p>
<p>1st. can I dynamically label these using .columnCount?</p>
<p>2nd. can I make the new columns invisible on creation?</p>
<p>Appreciate any help.</p>
<p>-G</p>
]]></content:encoded>
	</item>
</channel>
</rss>
