Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomize Datagrid columns visibility
    text
    copied!<p>I am loading my datagrid with data from a XML file as the example below. My XML file consists of 4 columns of data that shows into my datagrid. However I want the datagrid to show only certain columns based on an ArrayList that I am providing. In this example the ArrayList consists of two of the columns namely "Id" and "Name". I want to know what is the best way to do what I want. As it is I have already loaded the grid and I want to loop through the columns and check if the column name is contained in the list, then if not visible I set its width to Zero.</p> <pre><code>Or is there another way whereby before loading the grid itself I can do checks between the datagrid dataProvider and the ArrayList, and then populate the grid accordingly. So here the visible attribute will not be used. Anyone who can put some light on this? MY MXML &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"&gt; &lt;fx:Declarations&gt; &lt;fx:XML id="order" source="orderlist.xml"/&gt; &lt;s:XMLListCollection id="show" source="{order.order}"/&gt; &lt;s:ArrayList id="mylist"&gt; &lt;String&gt;Id&lt;/String&gt; &lt;String&gt;Name&lt;/String&gt; &lt;/s:ArrayList&gt; &lt;/fx:Declarations&gt; &lt;mx:DataGrid dataProvider="{show}" rowCount="4"&gt; &lt;mx:columns&gt; &lt;mx:DataGridColumn headerText="Order number" dataField="Id" /&gt; &lt;mx:DataGridColumn headerText="Name" dataField="Name" /&gt; &lt;mx:DataGridColumn headerText="Surname" dataField="Surname" /&gt; &lt;mx:DataGridColumn headerText="Age" dataField="Age"/&gt; &lt;/mx:columns&gt; &lt;/mx:DataGrid&gt; &lt;s:Button id="test_btn" click="Handler_to_set_DatagridColumns();"/&gt; &lt;/s:Application&gt; MY XML FILE &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Orderlist&gt; &lt;order Id="1" Name="Albert" Surname="Schineider" Age="45"/&gt; &lt;order Id="2" Name"Sara" Surname="Gutierrez" Age="25"/&gt; &lt;order&gt; Id="3" Name="Alain" Surname='Bulquee" Age="40"/&gt; &lt;/Orderlist&gt; Thanks for your help. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload