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

  • Home
  • SEARCH
  • 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 8610409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:07:20+00:00 2026-06-12T04:07:20+00:00

I am learning DOJO 1.6. I have data var data = [ { FirstName:

  • 0

I am learning DOJO 1.6.

I have data

var data = [
        { FirstName: 'xyz', Lastname: 'QSD', rollNo: '1', EntryDate: '2012-09-11T17:35:31.835+02:00' },
        { FirstName: 'abc', Lastname: 'qgr', rollNo: '2', EntryDate: '2012-08-11T17:35:31.835+02:00' }
        { FirstName: 'ert', Lastname: 'fgd', rollNo: '3', EntryDate: '2012-18-11T17:35:31.835+02:00' }
    ];

I want to sort it with respect to Last name or EntryDate and display in a tree format.

Thanks in Advance.


Multiple root data

data: [
            { id: 'world', name:'The earth', type:'planet', population: '6 billion'},
            { id: 'AF', name:'Africa', type:'continent', population:'900 million', area: '30,221,532 sq km',
                    timezone: '-1 UTC to +4 UTC', parent: 'world'},
                { id: 'EG', name:'Egypt', type:'country', parent: 'AF' },
                { id: 'KE', name:'Kenya', type:'country', parent: 'AF' },
                    { id: 'Nairobi', name:'Nairobi', type:'city', parent: 'KE' },
                    { id: 'Mombasa', name:'Mombasa', type:'city', parent: 'KE' },
                { id: 'SD', name:'Sudan', type:'country', parent: 'AF' },
                    { id: 'Khartoum', name:'Khartoum', type:'city', parent: 'SD' },
            { id: 'AS', name:'Asia', type:'continent', parent: 'world' },
                { id: 'CN', name:'China', type:'country', parent: 'AS' },
                { id: 'IN', name:'India', type:'country', parent: 'AS' },
                { id: 'RU', name:'Russia', type:'country', parent: 'AS' },
                { id: 'MN', name:'Mongolia', type:'country', parent: 'AS' },
            { id: 'OC', name:'Oceania', type:'continent', population:'21 million', parent: 'world'},
            { id: 'EU', name:'Europe', type:'continent', parent: 'world' },
                { id: 'DE', name:'Germany', type:'country', parent: 'EU' },
                { id: 'FR', name:'France', type:'country', parent: 'EU' },
                { id: 'ES', name:'Spain', type:'country', parent: 'EU' },
                { id: 'IT', name:'Italy', type:'country', parent: 'EU' },
            { id: 'NA', name:'North America', type:'continent', parent: 'world' },
            { id: 'SA', name:'South America', type:'continent', parent: 'world' }
        ],
  • 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-06-12T04:07:21+00:00Added an answer on June 12, 2026 at 4:07 am

    Javascript Array has a native function, called sort. This will off-the-shelf sort the values alphabetically. For the purpose of sorting non-string-values, we need to supply a sortingfunction. Like so, in regards to Lastname:

    data.sort(function(a,b) {
        var _A=a.Lastname.toLowerCase(), 
            _B=b.Lastname.toLowerCase();
    
        if (_A < _B) //sort string ascending
          return -1 
        if (_A > _B)
          return 1
        return 0 //default return value (no sorting)
    });
    

    If youre sorting against a date, you would need to initialize _A and _B to a Date.

    However, if youre aiming to represent the data in a dijit.Tree, there’s inbuilt method for sorting the Store, lets wrap data into a dojo/data/ItemFileReadStore and show in a tree. Tree will have a model, using ItemFileWriteStore – so that items can be modified:

    var sortableStore = new dojo.data.ItemFileReadStore({
        data: {
            identifier: 'rollNo',
            items: data
        },
        comperatorMap: {
            'EntryDate' : function(a,b) {
                var _A = new Date(a), _B = new Date(b);
                if(_A > _B) return 1;
                else if(_A == _B) return 0;
                else return -1;
            }
    });
    

    Using ‘store.fetch()’ API while setting the ‘sort’ parameter, you control the order of returned items. The EntryDate you will have to create a comperatorMap of functions, as with Array.sort() in order to sort it properly. See the documentation.

    var model = new dijit.tree.ForestStoreModel({
        rootLabel: 'Names',
        store: new dojo.data.ItemFileWriteStore({
            data: {
                identifier: 'rollNo',
                items: data, 
      // blank, initially - can fill in with 'data' to show non-sorted items until sort is called
                label: 'FirstName'
            }
        }) // blank itemsstore
    });
    
    var tree = new dijit.Tree({
        model: model
    });
    

    OK, All set – but problem with .fetch is, it runs with callbacks (onComplete) and is difficult to control in a recursive manner. Instead, the functionality put in THIS FIDDLE duplicates the store data and then sorts it via native array sort – as opposed to using SimpleQueryEngine.

    This will prove to give more reliable results – but does mess with DnD controllers and persist flag..

    See how store can sort its items returned by fetch here: fiddle. This however only sorts one ‘level’ at a time and does not perform deep sorts.
    IMO: The proper implementation of sort is a serverside sort, directly in the database query.

    http://dojotoolkit.org/reference-guide/1.8/dojo/data/ItemFileReadStore.html#custom-sorting

    http://dojotoolkit.org/reference-guide/1.8/dijit/Tree.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to learning dojo and I have come across the require() and
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
learning Jquery and integrating with PHP - getting there, but have one last challenge
(learning c#) I have a C# WPF application which when a certain form is
learning about loops (still a beginner) in VB.net. I have got the below code
Learning php! I have a sql database which contains a table called 'images' which
I am learning Dojo And trying to create a iWidget on WebShere Application server.
Learning jquery, so please be kind :) Using PHP, I have a table with
Learning to use the fork() command and how to pipe data between a parent
Learning C# here. I have a monthly process form whereby one can select to

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.