View Full Version : Reading Data from nonvisible objects in advanceddatagrid
shizny
04-07-2008, 11:59 PM
Hello,
I have setup an advanced datagrid with a heirachal array that represents a file selector as a tree control in the first column. It has four columns.
Column One: File name
Column Two: Date
column Three: author
I have a field in the dataprovider for the datagrid that is an id for all the files. When someone selects one of the filenames in the datagrid I want to pas the id to a function. I can get the id if I use a datagrid that only allows one selected cell,
event.target.parent.data.fileId
but when I use multiple cells I can't because somebody could select multiple cells at once and only fire the clicked event once passing only the information of the clicked cell and not all the cells that are affected because of the multiple selection. I can see all the data that I need when I look in the debugger at the
event.currentTarget.cellSelectionData variable, but I can't read it or do anything with it in actionscript cause it tells me.
Property cellSelectionData not found on mx.controls.AdvancedDataGrid and there is no default
I can't use the selectedCells property either because the data I am looking for is not visible on the advanceddatagrid, and therefore the row, column indicies do nothing for me.
Does anybody know what I can do to extract this information?
kahuja
04-08-2008, 08:40 AM
You have the grid bound to a dataprovider, right? If you get the row indexes, then you can fetch the same from the dataprovider (even the hidden data).
I dont know if there are any other ways and if there are better ways....
shizny
04-08-2008, 07:09 PM
I can't get that to work when I'm using a Hierachiacal dataProvider.
I have tried and will get something like column = 0 and row = 2 from the selectedCells variable indicies.
Then in the debugger I look at the dataprovider and have this...
http://www.wolffebrothers.com/dp.png
sleekdigital
04-08-2008, 07:27 PM
I don't understand why you would not use the selectedCells property. Shouldn't that have all the data in it? I thought selectedCells would be a reference to that part of the dataprovider, at least that's how selectedItem works in the list component.
shizny
04-08-2008, 07:44 PM
The selectedCells only gives me the row and column indicies which, in my case aren't matching up to anything in the dataprovider, at least nothing I can see.
sleekdigital
04-08-2008, 07:56 PM
What about the selectedItems property?
shizny
04-08-2008, 08:23 PM
selectedItems doesn't have anything but an empty array in it. The only variable I see that has what I need is the event.currentTarget.cellSelectionData
but I can't get at it, I don't know what type of variable it is but it has a yellow dot to the left of it in the debugger.
shizny
04-08-2008, 11:45 PM
should I try using flat data and grouping in the dataprovider instead of the Heirachial dataprovider?
sleekdigital
04-09-2008, 12:54 AM
Its internal which explains why you can't get to it. You would think they would expose this in some way.
At any rate this page in the docs shows an example of getting the data via the dataprovider and the event info...
http://livedocs.adobe.com/flex/3/html/advdatagrid_05.html
shizny
04-09-2008, 01:41 AM
Yeah, I tried that example code for code and it didn't work. Threw errors saying I was trying to reference a variable that didn't exist in the dataprovider. The only difference between what they had in that example and what I have is that my dataprovider is HierarchicalData whereas their example is flat data that has been grouped. I think that the Hierarchical aspect of my data is screwing stuff up but I can't imagine that there is no way to get this information.
shizny
04-09-2008, 05:48 PM
anyone, any other ideas 'cause I am STUCK BAD
kahuja
04-09-2008, 09:29 PM
Can you not try storing the IDs in a array as a user clicks on the cell, which mean that every click will fire an event and you save that in a Dictionary. Considering this is a toggle, you can check if the key exists, then delete, else add to it?
shizny
04-10-2008, 01:12 AM
yeah, I was doing that but when someone selects multiple cells at once only one click is registered and I miss all the cells that were selected but not clicked on.
kahuja
04-10-2008, 03:44 AM
someone selects multiple cells at once
Maybe I am hallucinating, but how can someone do that or are you suggesting that they have Multi-select option on? Can you not that that off the DG has a way to turn it off.
shizny
04-10-2008, 09:21 PM
yes, the multi-select option is set to true.
mcampster
04-11-2008, 02:53 PM
I'm not sure if this is the ONLY way to do it, but I think you should be looking at the events fired when you are changing row. Every change of row fires a ListEvent.Change.
If you add an event listener to your advanceddatagrid catching this event, within the event you will find a data property (maybe in the renderer) that contains all of the data that makes up that row, including your file id.
This might not be exactly what you need, but using various listevents may be the way to go.
mcampster
04-11-2008, 03:07 PM
I forgot to mention for the multipleRows -
if you loop over the event.currentTarget.selectedCells, use the row index of each current cell to access the entire row from the event.currentTarget.dataProvider at that index.
Then you can get the file id for each row, and do what you need to with it.
e.g.
var n:int = event.currentTarget.selectedCells.
for (var i:int = 0; i < n; i++)
{
var cell:Object = event.currentTarget.selectedCells[i];
// Get the row for the selected cell.
var data:Object = event.currentTarget.dataProvider[cell.rowIndex];
}
kahuja
04-11-2008, 04:58 PM
That was my point as well, no user can select multiple rows at a time, even if they do a Shift+click 10th row, it will internally fire 10 events for each of the rowChange and hence you can listen to those and keep in an array.
mcampster (http://www.actionscript.org/forums/member.php3?u=67653) took the time to explain in detail :-)
I have achieved something similar by the following:
1. extend the AdvancedDataGridItemRenderer class by providing a public property (eg a string named DataContainer)
2. override the data property to assign this new property:
override public function set data(value:Object):void
{
this._dataContainer = "some string, possibly xml";
}
3. assign an event handler to the (eg) listEvent.Change:
private function initApp():void
{
adg.addEventListener(ListEvent.CHANGE, listEventChangeHandler);
}
4. in the event handler the cell DataContainer can be accessed through the following code:
private function listEventChangeHandler(event:ListEvent):void
{
var s:String = MyItemRendererClass(event.itemRenderer).DataContai ner;
}
This technique allows unlimited properties to be assigned to a single cells. The tricky bit is ensuring step 2 assigns the correct metadata to the correct cell.
dhwingert
07-30-2008, 07:46 PM
I'm having exactly the same problem.
I've added a listener to my AdvancedDataGrid to the change event so I can keep a dictionary of selected items as prior posts suggested.
In the AdvancedDataGrid's creationComplete I have the following line:
grid.addEventListener(ListEvent.CHANGE, gridSelectionChange);
My grid has selectionMode="multipleRows".
I am finding when I click on a row in the grid I get the change event. Then when I shift click to select 10 more rows I am only getting one more change event for the row I actually shift clicked on. All the intervening rows that were also selected did not have events raised for them. So instead of getting 11 total events I only got two for the two endpoint rows I clicked on.
Am I missing something? I need to get to all of the data for the selected rows. I had all the same errors the original poster described when trying to use the Adobe Flex examples.
Help!
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.