Sorting a paginated DataGrid

Ever had the problem of a paginated DataGrid only sorting on the page that is currently being viewed? Yeah, pretty useless I know. I needed the whole set of data to be sorted and a quick search on tinernet suggested quite a few other people did too. Unfortunately none of the blogs I read seemed to have the exact answer. So here is the full working solution – I did this quickly so it may not be perfect. The pagination was done using this chaps implementation so if you’re not using that the below bit of code may not make much sense. A little bit of inspiration was taken from stackoverflow.

After sorting the ArrData list I realised that the refreshDataProvider method doesn’t even use it and instead uses some source property which is an Array representation of the list. Amazingly this has to be sorted separately! I don’t understand why ActionScript has this “feature”.

Synchronise Events with Bindings in Flex

I have recently had to delve into the world of Adobe Flex and ActionScript and wanted to share some of my trials and tribulations with it. As I’m not a massive fan of Flash or proprietary technologies I had to assume the work had been assigned to me as a punishment for crimes committed in a previous life. In fact, 2 months in, I’m not entirely convinced what embedded Flash has to offer over conventional html and javascript – especially considering the features available in HTML5. “Meh” pretty much sums up my feelings for Flex – perhaps I’ve been doing too much Java.

Having previously been programming JSF I found Flex quite … different. One notable difference being it’s easy approach to the Observer Pattern with Bindings and another being it’s asynchronous behaviour. As JSF does not have any features comparable to these so this was all unchartered territory for me. In particular, I was experiencing some difficulty with asynchronous calls and the ViewStack. Basically the application was Single-Sign-On and I didn’t want the home view to show until they had been authenticated. Simple right? All you have to do is a bind a Boolean which is set by a CairngormEvent when authentication succeeds. Next problem was that there was some data to show on the home screen. But because every service call is asynchronous the screen would load with a blank area which would only be filled-in once the service call had completed. Well, what’s the point in showing a page unless it’s ready to be shown. I now have 2 conditions that must be true and ChangeWatchers seem to be the only thing that are going to help me.

A capability to synchronise asynchronous events is all I could think of to achieve the desired result. So I created a SynchronisedChangeWatcher class. WARNING – this is an over-engineered solution so I’m not sure if I would recommend using it:

And it’s usage:

So doStuff() will be called when both UserLoggedIn and _CreationComplete properties change – Simplz!