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 6590967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:21:56+00:00 2026-05-25T17:21:56+00:00

OK, below is a simplified example of what I have to do. So far

  • 0

OK, below is a simplified example of what I have to do.

So far so good, works A1. The IDs are replaced by the friend name, and the column is sortable.

Now, I have to apply this to a system containing thousands of IDs and thousands of rows.

I tried it and wooooooooooo, it is so slow, impossible to deliver something like this to a client…

What would be, in your opinion, the best approach to achieve the same goal?

The only idea I had is instead of storing only the ID in the DB, to store the names as strings too… I just thing it is information I shouldn’t have to store…

Anybody have an idea? Another way to sort the rendered string instead of having to recall the fId.labelFunction(obj1, fId) on each row?

THANKS A LOT!

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.events.FlexEvent;

        [Bindable]
        private var _friendList:ArrayCollection = new ArrayCollection([
            {friend_id : 1},
            {friend_id : 3},
            {friend_id : 2},
            {friend_id : 2},
            {friend_id : 1},
            {friend_id : 2},
            {friend_id : 1},
            {friend_id : 3}
        ]);

        private function friendNameFromID(item:Object, column:DataGridColumn):String
        {
            var id:int = item[column.dataField];

            if (id == 1)
                return "Thomas";

            if (id == 2)
                return "Anthony";

            if (id == 3)
                return "George"

            return "";
        }

        private function sortFromFriendName(obj1:Object, obj2:Object):int
        {
            var value1:String = fId.labelFunction(obj1, fId);
            var value2:String = fId.labelFunction(obj2, fId);

            if (value1 == value2)
                return 0;
            else if (value1 > value2)
                return 1;
            else
                return -1;
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<mx:DataGrid id="myDataGrid" dataProvider="{_friendList}" width="90%" height="90%" horizontalCenter="0" verticalCenter="0">
    <mx:columns>
        <mx:DataGridColumn dataField="friend_id"/>
        <mx:DataGridColumn id="fId" dataField="friend_id" labelFunction="friendNameFromID" sortCompareFunction="sortFromFriendName"/>
    </mx:columns>
</mx:DataGrid>

  • 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-25T17:21:57+00:00Added an answer on May 25, 2026 at 5:21 pm

    Instead of doing a bunch of if(..) have u tried using a Dictionary object, setting the id as the key and the name as the value? If I’m not mistaken, access into a Dictionary is done using a hash function and is much faster than a series of if statements.

    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    initialize="buildNameDictionary()"
    >
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
    
            private var nameDictionary:Dictionary;
    
            [Bindable]
            private var _friendList:ArrayCollection = new ArrayCollection([
                {friend_id : 1},
                {friend_id : 3},
                {friend_id : 2},
                {friend_id : 2},
                {friend_id : 1},
                {friend_id : 2},
                {friend_id : 1},
                {friend_id : 3}
            ]);
    
            private function buildNameDictionary():void
            {
                nameDictionary= new Dictionary();
                nameDictionary[1] = "Thomas";
                nameDictionary[2] = "Anthony";
                nameDictionary[3] = "George";
            }
    
            private function friendNameFromID(item:Object, column:DataGridColumn):String
            {
                if(nameDictionary[item])
                    return nameDictionary[item] as String
    
                return "";
            }
    
            private function sortFromFriendName(obj1:Object, obj2:Object):int
            {
                var value1:String = fId.labelFunction(obj1, fId);
                var value2:String = fId.labelFunction(obj2, fId);
    
                if (value1 == value2)
                    return 0;
                else if (value1 > value2)
                    return 1;
                else
                    return -1;
            }
    
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    
    <mx:DataGrid id="myDataGrid" dataProvider="{_friendList}" width="90%" height="90%" horizontalCenter="0" verticalCenter="0">
        <mx:columns>
            <mx:DataGridColumn dataField="friend_id"/>
            <mx:DataGridColumn id="fId" dataField="friend_id" labelFunction="friendNameFromID" sortCompareFunction="sortFromFriendName"/>
        </mx:columns>
    </mx:DataGrid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Grid that looks something like the simplified example showed below. There
I've simplified my JavaScript code to the example below; this code is giving me
I have below a working query that needs to be simplified. The reason is
I have a deeply nested for-comprehension, simplified to 3 levels below: x, y, and
I have a page with more than one form. One form (see below example)
Below is a simplified example of a stored procedure I've created. DELIMITER // CREATE
Below is simplified example of what I am trying to achieve: class Product(models.Model): #
I coded some calculation stuff (I copied below a really simplifed example of what
The code below is a simplified version of my website. On my site, the
Below I have written a sample program that I have written to learn about

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.