View Full Version : Flex Data Grid - Update Column with variable (not from data provider)
Digitalosophy
July 27th, 2009, 10:56 AM
Hello,
I have a data grid who's data provider is set to an XML object.
<mx:DataGrid id="streamMonitorGrid" dataProvider="{_data.stream}" height="100%" width="100%">
<mx:columns>
<mx:DataGridColumn headerText="Title" dataField="@title"/>
<mx:DataGridColumn headerText="StationId" dataField="@stationId"/>
<mx:DataGridColumn headerText="Net Connection Status" id="nconnStatus" />
</mx:columns>
</mx:DataGrid>
Title and StationId data is set to XML attributes from the XMLObject and display with no problem.
The issue that I have ran into is I want to set the 3rd column (marked as "Net Connection Status") to a variable outside of the data provider XML object. The 3rd column should be set to any variable that I want - not within the XML object.
I cannot figure how to do the above, it almost seems like once a data provider is set you can't set a column to anything but data within the data provider.
Any idea's?
TIA
Krilnon
July 27th, 2009, 08:49 PM
Would it not be possible to merge the data that you want to go into the 3rd column into the XML that you're setting as the data provider? That seems like the easiest solution.
I thought that the whole reason that the dataProvider structure existed in the first place was so that you would know where all of the data for a given DataGrid was at once.
Digitalosophy
July 27th, 2009, 09:07 PM
That is possible Kril and looks like it's the easiest solution.
In this situation I'm running tests on the XML object that is set as the data provider. I want to have an extra column to display the results of the test (passed, failed, etc).
I was pretty shocked there wasn't an easy way to do this. There is an itemRenderer you can use but it's not very cut and dry.
Possibly the intent was what you had mentioned, update the datatProvider.
Thanks dude
Digitalosophy
July 28th, 2009, 09:09 AM
So that worked great Kril - thanks
453.0
July 28th, 2009, 09:20 AM
I cannot figure how to do the above, it almost seems like once a data provider is set you can't set a column to anything but data within the data provider.That's quiet true, but I can think of at least one hack. Use a custom label function to display data in your grid. With such a function, you can always check the third value and "suck" some data from a different source and display it. Obviously, the dataprovider items will always be just the ones that you read from XML, but that shouldn't stop you from displaying data in columns the way you want ( even if that means to read additional data from a different source ).
I didn't test this myself, but I can't think of a reason why this shouldn't work.
I hope I understood the problem right.
Digitalosophy
July 28th, 2009, 10:20 AM
It was actually really easy..
What I did was let's assume you have an XMLObject called "_data".
In there I have a bunch of nodes called stream with a bunch of attributes. What I am doing is taking attributes from each node, and just doing some basic logic on the data.
What I needed was an additional column with my custom results.
So assume you have a function that does that logic and comes up with a result.
You could just do
_data.stream[_testStreamPosition].@netConnResults = _netConnectionStatus; // netConnResults is my result and attribute I want to add to the DataGrid
Being that _data is bound to the DataGrid you can just add the field to the DataGrid and call it a day
[Bindable]
private var _data:XML;
<mx:DataGrid id="streamMonitorGrid" dataProvider="{_data.stream}" height="100%" width="100%">
<mx:columns>
<mx:DataGridColumn headerText="Title" dataField="@title"/>
<mx:DataGridColumn headerText="StationId" dataField="@stationId"/>
<mx:DataGridColumn headerText="Net Connection Status" id="nconnStatus" dataField="@netConnResults"/>
<mx:DataGridColumn headerText="Meta Data Status" id="mDataStatus" dataField="@metaResults"/>
</mx:columns>
</mx:DataGrid>
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.