Flexmaniacs - Sorting and Filtering and Drag and Drop

I went to two sessions this afternoon on Sorting and Filtering and on Drag and Drop. What struck me about these two is that despite some minor quirks they both showed how great Flex is.

The session on Sorting and Filtering by Scott Stroz was interesting and showed how fast Flex was at sorting and filtering large datasets of around 2000 or so records. It all seemed to happen in the blink of an eye!

The final session I went to was about Drag and Drop. For me this is the main reason for using a RIA over the traditional interface. Kevin Schmidt showed the easy and more difficult was to use Drag and Drop in Flex.

Here are my notes from the two sessions, a bit incomplete I'm afraid. I will link to the presentations if possible when they get posted.

Sorting data using ICollectionView Interface.

The class or property must implement the IcollectionView interface.

The underlying dataset does not change. You can step though the data using a cursor. You can use bookmarks and you can insert and delete data (that does modify data in the collection).

mx:DataGridColumn has a default setting of true for the sortable property.

If you use mx:itemRenderer or labelFunction property to format a column the default sort will give unexpected results.

You have to write a sortCompare function that will return 0 if two elements are the same and –1 or +1 depending on which is greater in the sort sequence.

To sort an ArrayCollection:

  • Create a new sort Object.
  • Add fields to the sort Object.

Drag and Drop - With List Controls

List Controls have drag and drop built in to them and it only needs to be turned on with the properties:
  • dragEnabled for the place to drag from.
  • dropEnabled for the place to drag to.
  • dragMoveEnabled to enable an object to be moved.
Add dragEnabled to list tag. Add DropEnabled to another, now you can drag between them. Add dragMoveEnabled to allow the things to be moved from the original list when they are dropped. Without that they are copied.

To drop between controls the elements must have the same data type, or do a type conversion on the drop event.

With Controls which don't have drag and drop built in

import DragManager, Drag.... Listen for events mouseDown and mouseMove in the thing you want to drag.
  • dragEnter
  • dragdrop
  • dragExit

When the slides are posted I will add a link to them if I can.

Comments
ion gion's Gravatar I can see that flex performs really well with intensive operations, from what you say. But I wonder, why would one sort so much data on the client side, what is the purpose of these operations. I also read about someone being able to parse 22K lines of XML with Flex, and the same hype, whats the purpose of these things in client side ?

Even if one uses Air as flex's running box, sqlite would sort/filter large data, faster than flex can ever achieve.
# Posted By ion gion | 6/27/07 3:03 PM
Foo's Gravatar Sometimes you can get your hands on the server side.
# Posted By Foo | 6/29/07 9:46 PM
Rajesh Bhadra's Gravatar hI,
How we can sort data of some complex data types inside a datagrid.
I have one arrayCollection and it contains lotsa of Value Object like userVO,customerVO.
Now these objects have first name,last name etc. I have used labelFunction for display.
I want to know how we can sort the data. I have also created a class extending SortField and have passed a parameter on which there should be sorting. But I m kinda confused how it works.
Can you help me out in this or point it out some referance article where sorting is based on complex data inside Datagrid.?
Thanks in advance.
# Posted By Rajesh Bhadra | 11/14/07 1:22 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.