tags:

views:

114

answers:

1

I am using an array to poulate a flash 8 datagrid, simple enough. I am also pre sorting the array by one of the fields, also simple enough.

I would like the sort arrow to be present when the grid is first populated, but it isn't!!

The user must click a header cell for the arrow to become visible. Is there any way to override this behaviour.

Thanks

A: 

Hi,

It's been a while since I've touched as2. Apparently I couldn't get things to work without hacks.

Normally you should've be able to get away with dg.dispatchEvent({type:"headerRelease"}), but no, that didn't seem to work. I've used the Debug > List Objects option to get the name of a column header, then called the onRelease() function on it. Apparently that worked only in an onEnterFrame, which I later deleted.

Here's my code, built with help from the documentation:

//hacky boolean to check if what we asked for was done
var selfClicked:Boolean = false;

myDP = new Array({name:"Chris", price:"Priceless"},{name:"Daisy", price:"Adequate"}, {name:"Nigel", price:"Cheap"});
dg.dataProvider = myDP;

onEnterFrame = function(){
    if(!selfClicked){
     //ask nicely
     dg.dispatchEvent({type:"headerRelease"});
     //no ? oh well...
     dg.content_mc.header_mc.hO0.onRelease();
     //fix for header label
     dg.content_mc.header_mc.fHeaderCell0._y = dg.content_mc.header_mc.fHeaderCell1._y;
     selfClicked = true;
     delete onEnterFrame;
    }
}

this.headerRelease = function(eventObject){
    //nicely hidden debugging gem here, thanks Jen deHaan!
    trace(mx.data.binding.ObjectDumper.toString(eventObject));
}
dg.addEventListener("headerRelease", this);

HTH, George

George Profenza
Hi George.Thank you so much, that is awesome and does indeed force a placement of the arrow on the grid.Couple of questions if I may.What is the dispatch event line doing as it seems to work still when that is removed.When I click on column 1 after the code has run, the header text moves differently to how it moves for the other columns ( abit ifficult to explain!).Many thanks anyway.
Dave
Hi Dave. Usually you should be able to dispatch an event from the component and that should've fixed it. You can wipe that off, I that wanted to show the attempt to do it in a less hacky manner. I see what you mean, the header text move diagonally, not horizontally. I think that might be because the sort arrow clip isn't created until the header is pressed and since we're hacking it, the text is shifted a bit up (not sure why exactly), but you can fix that if you add the following line after th hO0.onRelease():dg.content_mc.header_mc.fHeaderCell0._y = dg.content_mc.header_mc.fHeaderCell1._y;
George Profenza
Thanks George. I have found this works as welldg.content_mc.header_mc.hO0.onPress(); dg.content_mc.header_mc.hO0.onRelease();It seems to do the full press and release and this fixes it. Nice! Thanks again
Dave
Cool, am I to understand this is an acceptable answer ? ;)
George Profenza
Yes, this has solved my problem nicely (as log as nothing unforeseen is happening under the hood!!) Many thanks
Dave
@eventdave You should accept some answers to encourage more people to contribute to your other questions.
George Profenza