2014-04-16 65 views
0

我正在使用ng-grid,我已對其執行搜索功能,但是我想通過更改下拉值來更改orderby選項。ng-grid更改排序順序onchange of drop down

我希望提供下拉式的價值數據更改應該發生。

默認排序功能是在那裏工作的點擊標題表,但我需要改變下拉改變排序順序。

此代碼我從某處得到,但我不知道如何使用它?

$scope.gridOptions = { 
    data: 'gridData', 
    columnDefs: [ 
     {field: 'name', displayName: 'Name'}, 
     {field:'ageWord', displayName: 'Age'} 
    ], 
    sortInfo: { 
     fields: ['age'], 
     directions: ['asc'] 
    } 
}; 

回答

0

例如: - 如果你想通過name進行排序,你可以設置

sortInfo: { fields: ['name'], directions: ['asc']} 

這將通過名稱和升 你也想設置useExternalSorting = truegridOptions爲了你的網格。

我建議你看看

+0

它用於初始設置,我需要稍後改變排序順序 – anam

+0

排序應該隨着下拉改變 – anam

1

您需要定義的網格選項sortInfouseExternalSorting值,像這樣的docuexamples頁數:

$scope.gridOptions.useExternalSorting = true; 

$scope.gridOptions.sortInfo = { 
    fields: [$scope.selectedDropDownOption], // <-- or whatever variable used to store selected option from dropdown 
    directions: ['asc'] 
}; 
0

我用下面的代碼, ,,

HTML:

<input type="text" ng-model="sortColumn"></input> 
    <button type="button" class="btn" ng-click="updateSortInfo()">Sort</button> 

aap.js ::

$scope.updateSortInfo = function() { 
     $scope.gridOptions.sortBy($scope.sortColumn); 
    } 
0

到達這裏,而搜索的類似的事情解決。嘗試所有選項後,我已應用此。

//Disable Grid Ui Sorting through header 
    $scope.gridOptions.enableSorting = false; 
//Apply angular 'orderBy' filter to data for grid ui 
    $scope.resultSetTable = $filter('orderBy')($scope.gridData, 'YOUR_SORT_COLUMN'); 
// Apply data to grid ui 
    $scope.gridOptions.data = $scope.resultSetTable;