Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1145
sortMultiple
posted

The documentation for sortMultiple is a bit lacking: http://help.infragistics.com/jQuery/2012.1/ui.iggridsorting


I'm assuming it allows for sorting multiple columns, but the example doesn't give any sort of indication of how that's done and there's no documentation other than the sample line: 

$(".selector").igGridSorting("sortMultiple");

What I need to do is similar to what this user needed to do: http://ko.infragistics.com/community/forums/p/72571/367397.aspx#367397

The difference is I need to retrieve all the data filtered and sorted as the user has it on the web page (this is part of an export function).

By the way, this seems like very obvious functionality that ought to be added to the grids at some point. I just throw this out there in case you're taking suggestions for functionality. I'm sure I'm not the first person who's wanted to retrieve a copy of all the data (unpaged) as the grid is currently configured by the user. That is, using the sort and filter options the user currently has...

Anyway, I need to know how to apply the currently set sort to the filtereddatsource   from the above referenced forum post.

Thanks.

Parents
  • 6279
    Verified Answer
    posted

    Hi Pete,

    First off, let me apologize for the lack of a description on the sortMultiple method. The method is exposed as public due to implementation reasons - it's used by the multiple sorting's modal dialog if I'm not mistaken. This is why it doesn't accept any input parameters (because they're read internally).

    As for applying the multiple sorting in a single API call, I would recommend doing so like this:

    1. You need to access the igGrid's internal dataSource object and set the sorting expressions array for it. 
    2. Call the igGridSorting widget's sortMultiple() API method.

    (this will also update the grid's UI so no further steps are needed).

    However, if you want to access the grid's data when it's bound to local (client-side) data and paging, sorting and filtering are all local (client-side), then I have the solution just for you.

    It's basically the same as in the one from my reply on the forum thread you quoted but with one trick to it:

    //Filter the grid with a good enough condition so that we can have at least one record on the 2nd page
    $('#grid1').igGridFiltering("filter", [{fieldName: "Name",cond:"doesNotContain",expr:"Silverlight"}]);
    $("#grid1").data("igGrid").dataSource.settings.sorting.expressions = [ { fieldName: "IsPostponed",  dir: "desc"},  { fieldName: "EndDate",  dir: "asc"}];
    $('#grid1').igGridSorting("sortMultiple");
    
    
    var filteredSortedDataSource = $.extend(true, {}, $("#grid1").data("igGrid").dataSource);
    // we need to disable the paging feature so that the dataView() can represent only the filtered data.
    filteredSortedDataSource.settings.paging.enabled = false;
    // we need to make sure that sorting is applied to the filtered data
    filteredSortedDataSource.settings.sorting.applyToAllData = false;
    
    // Filter the copy of the igGrid's internal igDataSource in order to receive the desired data view
    filteredSortedDataSource = filteredSortedDataSource.filter($("#grid1").data("igGrid").dataSource.settings.filtering.expressions);
    filteredSortedDataSource = filteredSortedDataSource.sort($("#grid1").data("igGrid").dataSource.settings.sorting.expressions);
    
    var filteredSortedDataWithoutPaging = filteredSortedDataSource.dataView();
    


    The trick is in disabling the igDataSource sorting's applyToAllData option - then you can properly sort only the filtered data.
    As usual I'm attaching a running HTML sample page where you can see my suggestion in effect.

    If you have any other problems or questions, don't hesitate to let us know.

    PS: Sorry about this requiring knowledge of the igDataSource, but when compared with the requirements we have for the igGrid and igDataSource, this isn't such a high priority scenario for us to provide an easy solution to.
    By the way, there really aren't that many people (to the best of my knowledge, based on the forum and StackOverflow activity) that need to handle this scenario.
    PPS: If you wish for us to devote some time and effort in order to provide an out-of-the-box solution, please feel free to post a new feature idea in the corresponding page under your account.

    Cheers,
    Bobby 

    t77475.zip
Reply Children