简体   繁体   中英

How to remove sorting on ui-grid before reload another data set ui-grid

Im using ui-grid to load my data set. Here is my requirment;

step 01: I want to load dataset_01 ( scope.gridOptions.data = res_01; ).

step 02: I want to sort by First Name (Click by firstname column).

step 03: Click an external button and Reload ui-grid with an another data set ( scope.gridOptions.data = res_02; ).

Here is my result:

在此处输入图片说明

I dont want sort by First Name here for second dataset. I want data without sorting. How can I do it ?

Expected result:

在此处输入图片说明

So I want to reload second data set without sorting (Means I want to remove first sorting before load second data set). how can I reset my ui-grid before load next data set ( scope.gridOptions.data = res_01; ).

How can I do it ?

Thank you. :)

You can set the sort property of your columnDefs to:

sort: {
   direction: undefined,
}

and call for grid refresh using $sope.gridApi.core.refresh() after. This should re-render the whole grid and get rid of the sorting.

Visit this page: http://ui-grid.info/docs/#/api/ui.grid.core.api:PublicApi

After having instantiated your gridApi, you can just call:

$scope.gridApi.core.refresh();

Hope that helps! :)

  1. Create your gridoption like this

example

$scope.gridOptions = {
    useExternalPagination: true,
    useExternalSorting: false,
    enableFiltering: false,
    enableSorting: true,
    enableRowSelection: false,
    enableSelectAll: false,
    enableGridMenu: true,
    enableFullRowSelection: false,
    enableRowSelection: false,
    enableRowHeaderSelection: false,
    paginationPageSize: 10,
    enablePaginationControls: false,
    enableRowHashing: false,
    paginationCurrentPage:1,
    columnDefs: [
        { name: "FristName", displayName: "Frist Name", width: '6%', sort: { direction: undefined }  },
    ]
};

after that you can remove the sorting where you want using below code

$scope.RemoveSorting = function ()
{
    $scope.gridOptions.columnDefs.forEach(function (d) {

        d.sort.direction = undefined;
    })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM