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.