View Full Version : Toggle single/double sort on datagrid
mrmodus
09-02-2009, 02:31 PM
I have a datagrid with sortable columns. The grid is populated from XML. The columns are "Description", "Price" and "Quantity". One of the fields in the XML is called "isMine" and is a bit field (1 or 0). The isMine field will not be one of the displayed columns however I'd like to be able to group by it. So if a checkbox was checked I'd like the sorting to be by "isMine descending" then whichever column the user chose to sort by. So isMine then price. Or isMine then quantity. If the checkbox is _not_ checked I just want the user selected column to be sorted by. So if not checked just sort by price etc.
Hopefully that makes sense.
Any help would be appreciated. I'm a bit of a newb with this stuff.
:confused:
Peter Cowling
09-03-2009, 01:29 PM
Hopefully that makes sense.
Vaguely.
I would post your code, as it would probably clarify things.
mrmodus
09-03-2009, 02:22 PM
Thanks for the reply. I'll post the request, the datagrid and the current custom sorters I have now. I will also post a snippet example of what the returned XML would look like. One of the xml fields is called "isMine" which is "true" if the item is owned by the website owner, and "false" if the item is owned by another person. What I want is a checkbox that if clicked will display all the isMine=true items in a group first, then all the isMine=false items after that, yet still sort by price, quantity, whatever. So basically grouping the two types of results together while still sorting by the user selection of price or quantity etc. I found a tutorial online that talks about programmatically sorting by multiple fields but it seemed to only work on an ArrayCollection and threw an error when I tried to implement it with the XML results.
<!-- Data Request -->
<mx:HTTPService url="{siteURL}/includes/tnProxy.cfm" method="GET" id="ticketData" result="ticketContentHandler(event)" resultFormat="e4x">
<mx:request>
<proxyType>Tickets</proxyType>
<websiteConfigID>{configIDIN}</websiteConfigID>
<eventID>{eventIDIN}</eventID>
</mx:request>
</mx:HTTPService>
<!-- Sample XML -->
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfTicketGroup>
<TicketGroup>
<ActualPrice>853.00</ActualPrice>
<PriceSort>853.0001</PriceSort>
<ID>669223682</ID>
<IsMine>false</IsMine>
<Row>12</Row>
<Section>BL 203</Section>
<ValidSplits>
<int>4</int>
<int>2</int>
</ValidSplits>
</TicketGroup>
<TicketGroup>
<ActualPrice>2073.00</ActualPrice>
<PriceSort>2073.0001</PriceSort>
<ID>669224623</ID>
<IsMine>true</IsMine>
<Row>17</Row>
<Section>224</Section>
<ValidSplits>
<int>4</int>
<int>2</int>
</ValidSplits>
</TicketGroup>
</ArrayOfTicketGroup>
<!-- Datagrid to display XML results -->
<mx:DataGrid id="ticketGrid" width="100%" height="100%" dataProvider="{tixXML}" rowHeight="40" wordWrap="true" resizableColumns="true" verticalAlign="middle" paddingBottom="2" paddingLeft="2" paddingRight="2" paddingTop="2" borderThickness="1" rollOverColor="#dbdcc9" selectionColor="#B5BFA7" textAlign="center" cornerRadius="5" borderStyle="solid" borderColor="#b7babc">
<mx:columns>
<mx:DataGridColumn width="75" dataField="Section" headerText="Sec" wordWrap="true" resizable="true" />
<mx:DataGridColumn width="60" dataField="Row" headerText="Row" wordWrap="true" resizable="true" />
<mx:DataGridColumn width="60" headerText="Quantity" resizable="false" sortCompareFunction="compareQuantity" itemRenderer="renderers.rend_Quantity"/>
<mx:DataGridColumn width="85" dataField="ActualPrice" headerText="Our Price" wordWrap="false" textAlign="center" resizable="true" sortCompareFunction="comparePrice" itemRenderer="renderers.rend_Price"/>
<mx:DataGridColumn width="55" textAlign="center" resizable="false" sortable="false" itemRenderer="renderers.rend_BuyButton"/>
</mx:columns>
</mx:DataGrid>
// custom sorter for sorting Actual Price numerically.
private function comparePrice(itemA:Object, itemB:Object):int
{
return ObjectUtil.numericCompare(itemA.PriceSort, itemB.PriceSort);
}
// custom sorter for sorting Quantity of tickets numerically.
private function compareQuantity(itemA:Object, itemB:Object):int
{
return ObjectUtil.numericCompare(itemA.ValidSplits.int[0], itemB.ValidSplits.int[0]);
}
Peter Cowling
09-04-2009, 07:29 AM
A position from which there are lots of choices.
The choices are basically about the role of the data, and the form of the data.
You could engineer solutions with xml,xmllist,xmllistcollection or array,arraycollection, and probably so on.
You could do sorts, as you have now, on objects taken from the datagrid. And you can work on the data, and make it drive the view/grid.
From your position, you could probably use the existing sort approach along with an xmllistcollection or arraycollection and get a solution.
I would not do that. My specific approach would be to use an arraycollection, do all my sorting, and then update the view.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.