Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

Sorting radcombobox in client side

$
0
0

I found the client-side sorting method in one of the answers to not work as expected. So I changed it and came up with following method, that I found worked perfectly.  The second parameter of sortOrder can be either 'asc' or 'desc'.

 

functionsortByItemText(comboBox, sortOrder) {
 
    comboBox.trackChanges();
 
    varitems = comboBox.get_items();
 
    vartempArray = items._array;
 
    if(sortOrder === "asc") {
        tempArray.sort(function(a, b) {
            if(a && b && a.get_text() > b.get_text()) return1;
            if(a && b && a.get_text() === b.get_text()) return0;
            if(a && b && a.get_text() < b.get_text()) return-1;
        });
    } else{
        tempArray.sort(function(a, b) {
            if(a && b && a.get_text() > b.get_text()) return-1;
            if(a && b && a.get_text() === b.get_text()) return0;
            if(a && b && a.get_text() < b.get_text()) return1;
        });
 
    }
 
    items.clear();
 
    for(vari = 0; i < tempArray.length; i++) {
        varcomboItem = newTelerik.Web.UI.RadComboBoxItem();
        comboItem.set_text(tempArray[i].get_text());
        comboItem.set_value(tempArray[i].get_value());
        items.insert(i, comboItem);
    }
    comboBox.commitChanges();
    return;
}

Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>