DHTMLX Docs & Samples Explorer

Sorting items

Sort by type asc | desc
Sort by name asc | desc
Sort by size asc | desc

Order remains while changing types

F-icon
F-tiles
F-table
Source
<script src="../../codebase/dhtmlxcommon.js" type="text/javascript"></script>
<script src="../../codebase/dhtmlxfolders.js" type="text/javascript"></script>
<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxfolders.css">    
<script>
var myFolders;
function doOnLoad() {
    myFolders = new dhtmlxFolders("folders_container");
    myFolders.setItemType("ficon");
    myFolders.setUserData("icons_src_dir", "../common/images");
    myFolders.loadXML("../common/files_ext.xml", "../../codebase/types/ficon.xsl");
}
function changeType(type) {
    myFolders.setItemType(type, "../../codebase/types/" + type + ".xsl");
}
function sortByName(a, b) {
    var aName = a.data.dataObj.getAttribute("name");
    var bName = b.data.dataObj.getAttribute("name");
    if (aName > bName);
    return 1;
    else if (aName == bName);
    return 0;
    else;
    return - 1;
}
function sortBySize(a, b) {
    try {
        var aSize = parseInt(a.data.dataObj.getElementsByTagName("filesize")[0].firstChild.nodeValue);
    } catch(e) {
        var aSize = 0;
    }
    try {
        var bSize = parseInt(b.data.dataObj.getElementsByTagName("filesize")[0].firstChild.nodeValue);
    } catch(e) {
        var bSize = 0;
    }
    return aSize - bSize;
}
function sortByType(a, b) {
    var aType = a.data.dataObj.getAttribute("type");
    var bType = b.data.dataObj.getAttribute("type");
    if (aType > bType);
    return 1;
    else if (aType == bType);
    return 0;
    else;
    return - 1;
}
</script> <div style="position:relative;"> <img src="../common/images/samples_frame.gif" width="436" height="513" alt="" border="0"> <div id="folders_container" style="width:396px;height:396px;overflow:hidden;position:absolute;top:65px;left:20px;border:0px solid red;"></div> </div> Sort by type <span style="cursor:pointer;color:blue;text-decoration:underline;" onclick="myFolders.sortItems(sortByType,'asc');">asc</span> | <span style="cursor:pointer;color:blue;text-decoration:underline;" onclick="myFolders.sortItems(sortByType,'desc');">desc</span><br> Sort by name <span style="cursor:pointer;color:blue;text-decoration:underline;" onclick="myFolders.sortItems(sortByName,'asc');">asc</span> | <span style="cursor:pointer;color:blue;text-decoration:underline;" onclick="myFolders.sortItems(sortByName,'desc');">desc</span><br> Sort by size <span style="cursor:pointer;color:blue;text-decoration:underline;" onclick="myFolders.sortItems(sortBySize,'asc');">asc</span> | <span style="cursor:pointer;color:blue;text-decoration:underline;" onclick="myFolders.sortItems(sortBySize,'desc');">desc</span><br> <h3>Order remains while changing types</h3> <input type="radio" name="switch" onclick="changeType(this.value)" value="ficon" checked> F-icon<br> <input type="radio" name="switch" onclick="changeType(this.value)" value="ftiles"> F-tiles<br> <input type="radio" name="switch" onclick="changeType(this.value)" value="ftable"> F-table<br>