jQuery UI Widgets Forums Grid Sort custom

This topic contains 3 replies, has 2 voices, and was last updated by  Dimitar 8 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Sort custom Posts
  • Sort custom #82231

    amatost
    Participant

    Hello everyone,
    I have to order my jqGrid especially, exactly this way
    3 – P
    8 – D
    8 – C
    6 – A
    in particular:
    P
    P
    P
    D
    D
    D
    D
    D
    D
    D
    D
    C
    C
    C
    C
    C
    C
    C
    C
    A
    A
    A
    A
    A
    A

    How can I do? Help me please.
    Thank you all.

    Sort custom #82243

    Dimitar
    Participant

    Hello amatost,

    jqxGrid allows for the implementation of custom sorting, as shown in the following demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/customsorting.htm?arctic.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Sort custom #82268

    amatost
    Participant

    Thanks, Dimitar

    but unfortunately I am not an experienced programmer, I have to implement this code?:

    
                var customsortfunc = function (column, direction) {
                    var sortdata = new Array();
    
                    if (direction == 'ascending') direction = true;
                    if (direction == 'descending') direction = false;
    
                    if (direction != null) {
                        for (i = 0; i < data.length; i++) {
                            sortdata.push(data[i]);
                        }
                    }
                    else sortdata = data;
    
                    var tmpToString = Object.prototype.toString;
                    Object.prototype.toString = (typeof column == "function") ? column : function () { return this[column] };
                    if (direction != null) {
                        sortdata.sort(compare);
                        if (!direction) {
                            sortdata.reverse();
                        }
                    }
                    source.localdata = sortdata;
                    $("#jqxgrid").jqxGrid('updatebounddata', 'sort');
                    Object.prototype.toString = tmpToString;
                }
    
                // custom comparer.
                var compare = function (value1, value2) {
                    value1 = String(value1).toLowerCase();
                    value2 = String(value2).toLowerCase();
    
                    try {
                        var tmpvalue1 = parseFloat(value1);
                        if (isNaN(tmpvalue1)) {
                            if (value1 < value2) { return -1; }
                            if (value1 > value2) { return 1; }
                        }
                        else {
                            var tmpvalue2 = parseFloat(value2);
                            if (tmpvalue1 < tmpvalue2) { return -1; }
                            if (tmpvalue1 > tmpvalue2) { return 1; }
                        }
                    }
                    catch (error) {
                        var er = error;
                    }
    
                    return 0;
                };
    

    could you kindly give me an example related to my case?

    Best regards,
    Amato

    • This reply was modified 8 years, 2 months ago by  amatost.
    Sort custom #82302

    Dimitar
    Participant

    Hi Amato,

    I just now realise that you would like to sort alphabetically, but descending. If so, you do not really need to implement custom sorting. Just call the method sortby and pass ‘desc’ as second parameter. Here is an example with this method: http://jsfiddle.net/jqwidgets/7yWdu/. If you wish your grid to be sorted by default, call sortby in the ready callback function.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.