Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:33:52+00:00 2026-05-25T12:33:52+00:00

I have a spark DataGrid component with several columns and I want to have

  • 0

I have a spark DataGrid component with several columns and I want to have my application default to descending order on the first column in the DataGrid. I would like to use the built-in default sort that occurs when clicking the top header once. I have no need to sort the ArrayCollection I’m working with or change what the comparators are.

I also want any user-generated sorting such as clicking on a different column’s header to override the default sorting.

Does anyone have any ideas on how to go about this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:33:53+00:00Added an answer on May 25, 2026 at 12:33 pm

    Just use sortByColumn method:

    var columnIndexes:Vector.<int> = Vector.<int>([ 0 ]);
    dataGrid.sortByColumns(columnIndexes, true);
    

    Here is a full example:

    DataGridSort.mxml

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        creationComplete="sortDataGrid();">
    
        <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.ArrayList;
    
            [Bindable]
            private var dataProvider:ArrayCollection = new ArrayCollection(
            [
                new Product("iPad", "Detroit", 599),
                new Product("iPod", "Burbank", 49),
                new Product("iPod Nano", "Burbank", 39),
                new Product("Flash Drive", "Burbank", 59),
                new Product("iPod", "Burbank", 49),
                new Product("Galaxy Tab", "Coldbridge", 499),
                new Product("HTC Hero", "Abidjan", 700)
            ]);
    
            private function sortDataGrid():void
            {
                // you can also use Vector.<int>([ 0, 1 ]); to sort by first 2 columns
                var columnIndexes:Vector.<int> = Vector.<int>([ 0 ]);
    
                // set 2nd argument to true to show sorting triangle
                dataGrid.sortByColumns(columnIndexes, true);
            }
    
        ]]>
        </fx:Script>
    
        <s:DataGrid id="dataGrid" horizontalCenter="0" verticalCenter="0" width="200"
            dataProvider="{dataProvider}">
            <s:columns>
                <s:ArrayCollection>
                    <s:GridColumn dataField="name"/>
                    <s:GridColumn dataField="location"/>
                    <s:GridColumn dataField="price"/>
                </s:ArrayCollection>
            </s:columns>
        </s:DataGrid>
    
    </s:Application>
    

    Product.as

    package
    {
    import flash.events.EventDispatcher;
    
    public class Product extends EventDispatcher
    {
    
        public function Product(name:String = null, location:String = null, price:Number = 0)
        {
            super();
    
            this.name = name;
            this.location = location;
            this.price = price;
        }
    
        public var name:String;
    
        public var location:String;
    
        public var price:Number;
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a spark datagrid that wordwraps all rows where relevant.
I have a view like this in my Flex mobile Application: <s:View xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark
I have a datagrid where one column calls a custom an itemEditor like; <mx:DataGridColumn
If I have 10 columns in a Spark datagrid, and some headers need to
I have a spark DataGrid which has more rows than its size. I want
I am writing a flex application and I have two Spark TextAreas. I want
I have a spark datagrid on a mobile application, I set the interactionMode=touch and
i have used spark datagrid for my mobile application . my problem is last
I have spark.components.TileGroup that contains buttons. I would like the buttons to appear like
I have a mx:Datagrid in witch I'd like to add a combobox as item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.