Filter columns in flex datagrid using CheckBox
I have a flex datagrid开发者_运维问答 with 4 columns.I have a comboBox with 4 checkboxes,containing the column names of datagrid as its label.I want the datagrid to display only those columns which are selected in combobox.Can anyone tell me how this filtering of columns in datagrid can be done?
Thanks in advance.
You can manipulate the columns attached to the data grid using the .columns
property. Bear in mind that this method is a getter and returns you a copy of the list of columns on the datagrid, so if you manipulate its contents you have to apply those changes back to the data grid using the equivalent setter, e.g.
<mx:DataGrid id="dg" />
in ActionScript code
var columns:Array = dg.column;
columns.push(new DataGridColumn("hello"));
dg.columns = columns;
In your case you could hold your master list of columns in a separate array and push them onto the data grid as the user checks and un-checks them from the list in your comboBox.
Alternatively you can iterate through the column list looking for the ones which are checked in your comboBox and set their .visible
property accordingly.
HTH
精彩评论