@@ -16,6 +16,10 @@ json files to show - one sorted ASC, one sorted DESC, and one not sorted. To fu
16
16
is using external sorting, the external sort routine (consisting of me manually editing json files) got bored
17
17
of sorting after the first 10 or so rows.
18
18
19
+ We allow sorting by the first and second columns, so that we can show a default sort and that default sort
20
+ indicator being removed even when using external sorting. Our external sort routine ignores that second
21
+ column however, so sorting by it has no effect.
22
+
19
23
<example module="app">
20
24
<file name="app.js">
21
25
var app = angular.module('app', ['ngTouch', 'ui.grid']);
@@ -26,13 +30,17 @@ of sorting after the first 10 or so rows.
26
30
useExternalSorting: true,
27
31
columnDefs: [
28
32
{ name: 'name' },
29
- { name: 'gender', enableSorting: false},
33
+ { name: 'gender', sort: {
34
+ direction: uiGridConstants.DESC,
35
+ priority: 1
36
+ }
37
+ },
30
38
{ name: 'company', enableSorting: false}
31
39
],
32
40
onRegisterApi: function( gridApi ) {
33
41
$scope.gridApi = gridApi;
34
42
$scope.gridApi.core.on.sortChanged( $scope, function( grid, sortColumns ) {
35
- if( sortColumns.length === 0 ){
43
+ if( sortColumns.length === 0 || sortColumns[0].name !== $scope.gridOptions.columnDefs[0].name ){
36
44
$http.get('/data/100.json')
37
45
.success(function(data) {
38
46
$scope.gridOptions.data = data;
@@ -72,7 +80,7 @@ of sorting after the first 10 or so rows.
72
80
</file>
73
81
<file name="index.html">
74
82
<div ng-controller="MainCtrl">
75
- <div ui-grid="gridOptions" class="grid"></div>
83
+ <div id="grid1" ui-grid="gridOptions" class="grid"></div>
76
84
</div>
77
85
</file>
78
86
<file name="main.css">
@@ -81,4 +89,57 @@ of sorting after the first 10 or so rows.
81
89
height: 250px;
82
90
}
83
91
</file>
92
+ <file name="scenario.js">
93
+ var gridTestUtils = require('../../test/e2e/gridTestUtils.spec.js');
94
+
95
+ describe('307 tutorial', function() {
96
+ it('grid should have three visible columns', function () {
97
+ gridTestUtils.expectHeaderColumnCount( 'grid1', 3 );
98
+ });
99
+
100
+ it('header values should be as expected', function () {
101
+ gridTestUtils.expectHeaderCellValueMatch( 'grid1', 0, 'Name' );
102
+ gridTestUtils.expectHeaderCellValueMatch( 'grid1', 1, 'Gender' );
103
+ gridTestUtils.expectHeaderCellValueMatch( 'grid1', 2, 'Company' );
104
+ });
105
+
106
+ it('grid should be unsorted by default', function () {
107
+ gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
108
+ gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
109
+ });
110
+
111
+ it('sort by name by clicking header', function () {
112
+ gridTestUtils.clickHeaderCell( 'grid1', 0 );
113
+ gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Beryl Rice' );
114
+ gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Bruce Strong' );
115
+ });
116
+
117
+ it('reverse sort by name by clicking header', function () {
118
+ gridTestUtils.clickHeaderCell( 'grid1', 0 );
119
+ gridTestUtils.clickHeaderCell( 'grid1', 0 );
120
+ gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Wilder Gonzales' );
121
+ gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Valarie Atkinson' );
122
+ });
123
+
124
+ it('return to original sort by name by clicking header', function () {
125
+ gridTestUtils.clickHeaderCell( 'grid1', 0 );
126
+ gridTestUtils.clickHeaderCell( 'grid1', 0 );
127
+ gridTestUtils.clickHeaderCell( 'grid1', 0 );
128
+ gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
129
+ gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
130
+ });
131
+
132
+ it('sort ignored on second column', function() {
133
+ gridTestUtils.clickHeaderCell( 'grid1', 1 );
134
+ gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
135
+ gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
136
+ });
137
+
138
+ it('sort disabled on last column', function() {
139
+ gridTestUtils.clickHeaderCell( 'grid1', 2 );
140
+ gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
141
+ gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
142
+ });
143
+ });
144
+ </file>
84
145
</example>
0 commit comments