jQuery UI Widgets Forums Plugins Data Adapter Sort dataAdapter records

This topic contains 4 replies, has 3 voices, and was last updated by  admin 1 year, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Sort dataAdapter records #76184

    jb
    Participant

    Hi!
    I’m not sure it’s the right place for this question.. anyhow, please help me out.
    I have a grid the gets his data from binded xml. I need to sort the content of the table on multiple columns, which isn’t available using the sort functionalities of the grid (only 1 column allowed).
    I was thinking of placing a sort feature in the “loadComplete” event of dataAdapter, but I have no idea how I should do that.
    You may use “demos/jqxgrid/bindingtoxml.htm” to demonstrate how I should acheive this.
    Thanks for your help and for your great widgets!

    Sort dataAdapter records #76187

    Vladimir
    Participant

    Hello jb,

    You can use the beforeLoadComplete callback function to implement this logic.

                var dataAdapter = new $.jqx.dataAdapter(source, {
                    beforeLoadComplete: function (records) {
                        // implement sorting logic here that modifies records array
                        return records;
                    }
                });

    Best Regards,
    Vladimir

    jQWidgets Team
    http://www.jqwidgets.com

    Sort dataAdapter records #76189

    jb
    Participant

    Thanks Vladimir.
    I used “alasql” third-party library to sort my records as such:

    var dataAdapter = new $.jqx.dataAdapter(source, {
    beforeLoadComplete: function (records) {
    var sorted_records = alasql(‘SELECT * FROM ? ORDER BY PROJECT_PEATS DESC, PROJECT_MER DESC, PROJECT_NAME ASC’,[records]);
    records = sorted_records;
    return records;
    }
    });

    In my application, I’ve tied an function in the “loadComplete” event of the same DataAdapter. This function finds the rowID of a specific record (whatimlookingfor) and then applies the “selectrow” method find get it. It worked well until I implemented the “beforeLoadComplete” callback function above. The rowID I now get is the one before the records are sorted. Can you help me sort this out?

    var object = dataAdapter_grid.records;
    for (var i = 0; i < object.length; i++)
    {
    var str = object[i].fieldimlookinginto;
    if(str == whatimlookingfor){ rowID=object[i].uid; break;}
    }
    $(‘#jqxgrid’).jqxGrid(‘selectrow’, rowID);

    Sort dataAdapter records #76210

    Vladimir
    Participant

    Hello jb,

    The reason for that is that the selectrow function uses boundID and not element id to select an element. Read the API Reference of the jqxGrid for more information.

    You can try using something like:

    index = $('#jqxgrid').jqxGrid('getrowboundindexbyid', rowID);
    $('#jqxgrid').jqxGrid('selectrow', index);

    Best Regards,
    Vladimir

    jQWidgets Team
    http://www.jqwidgets.com

    Sort dataAdapter records #100654

    admin
    Keymaster

    Grid Multi Column Sorting will be part of the upcoming release: https://www.jqwidgets.com/grid-multi-column-sorting/

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

You must be logged in to reply to this topic.