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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:42:13+00:00 2026-06-13T11:42:13+00:00

I was about to make a basic file manager using ExtJS 4 . The

  • 0

I was about to make a basic file manager using ExtJS 4. The problem I faced now is: how to make custom sorting for grid panel when clicking the columns.

Imagine we have store fields:

[
    { name: "is_dir", type: "boolean" },
    { name: "name",   type: "string"  },
    { name: "size",   type: "int"     }
]

And the data which comes from an array:

[
    { is_dir: true,  name: "..",        size: 0    },
    { is_dir: false, name: "file2.txt", size: 512  },
    { is_dir: true,  name: "folder2",   size: 0    },
    { is_dir: false, name: "file3.txt", size: 1024 },
    { is_dir: true,  name: "folder1",   size: 0    },
    { is_dir: true,  name: "file1.txt", size: 1024 },
    // ...
]

The idea is to make sorting like in any file manager (e.g. Total Commander, MC, FAR, etc) so, that:

  • the item with name “..” is always placed at the top
  • dirs go after “..” (if exists) in sorted order
  • files go after dirs (if exist) in sorted order

For example, the output with sorting by name and by size should be:

^ Name           | Size               Name             | ^ Size
-----------------------               -------------------------
..               | 0                  ..               | 0
folder1          | 0                  folder1          | 0
folder2          | 0                  folder2          | 0
file1.txt        | 1024               file2.txt        | 512
file2.txt        | 512                file1.txt        | 1024
file3.txt        | 1024               file3.txt        | 1024

I’ve tried to write custom sorterFn for store sorters property, however it didn’t help. I believe there should be some easy solution for that.

  • 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-13T11:42:14+00:00Added an answer on June 13, 2026 at 11:42 am

    I have forked @Alexey’s answer with short sorting algorithm. Additionally, I fixed the problem with double sorting (because of this.callParent(arguments); which runs the basic sorting from the parent method). Here is the solution that works perfectly for me:

    sort: function(sorters) {
        sorters = sorters || { property: "name", direction: "ASC" };
        var mod = sorters.direction.toUpperCase() === "DESC" ? -1 : 1;
    
        this.sorters.clear();        // these lines are needed
        this.sorters.add(sorters);   // to update the column state
    
        this.doSort(function(a, b) {
            var a_type = a.get("is_dir"),
                b_type = b.get("is_dir"),
                a_name = a.get("name"),
                b_name = b.get("name");
    
            if (a_name === "..") return -1;
            if (a_type === b_type) {
                var a_prop = a.get(sorters.property),
                    b_prop = b.get(sorters.property);
    
                if (a_prop === b_name) {
                    return (a_name < b_name ? -1 : 1) * mod;
                } else {
                    return (a_prop < b_prop ? -1 : 1) * mod;
                }
            } else {
                return b_type - a_type;
            }
        });
    }
    

    DEMO: http://jsfiddle.net/cvdNW/186/

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

Sidebar

Related Questions

I'm not expert about css menus. But I know basic system to make css
We're about to make data transformation from one system to another using SSIS. We
hopefully this is a basic question about make pattern rules: I want to use
I am about to make a game using python and libtcod roguelike game library.
Got about a 400 MB .txt file here that is delimited by '|'. Using
BASIC PROBLEM: I want my app to be able to make calls to the
I don't really know anything about make or makefile scripts, so I'm hoping someone
I read the german article about Make on Wikipedia and found the following 2
I am about to make some major changes to my Mercurial repositories. As I
I'm about to make a fool out of myself, but I've noticed many friendly

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.