Skip to content

Commit 69eb586

Browse files
author
skozlov
committed
Were added statuses request for ordres and default sorting for server pagination
1 parent 271576f commit 69eb586

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

demo/bootstrap/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h4>Additional Demos</h4>
168168
ng-model="status"
169169
ng-change="filter()">
170170
<option value="">All Statuses</option>
171-
<option ng-repeat="option in statusOptions track by option.value"
171+
<option ng-repeat="option in UI.statusOptions track by option.value"
172172
value="{{option.value}}">{{option.text}}
173173
</option>
174174
</select>

demo/bootstrap/js/serverPaginationApp.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@
1515
data: [],
1616
getData: myAppFactory.getOrdersData,
1717
sort: {
18-
predicate: 'name',
18+
predicate: 'orderNo',
1919
direction: 'asc'
2020
}
2121
};
22+
$scope.UI = {};
2223
$scope.gridActions = {};
24+
myAppFactory.getStatuses().success(function (resp) {
25+
$scope.UI.statusOptions = resp;
26+
});
2327
}
2428

2529
function MyAppFactory($http) {
2630
var herokuDomain = 'https://server-pagination.herokuapp.com';
2731
return {
28-
getOrdersData: getOrdersData
32+
getOrdersData: getOrdersData,
33+
getStatuses: getStatuses
2934
};
3035

3136
function getOrdersData(params, callback) {
3237
$http.get(herokuDomain + '/orders' + params).success(function (response) {
3338
callback(response.orders, response.ordersCount);
3439
});
3540
}
41+
42+
function getStatuses() {
43+
return $http.get(herokuDomain + '/orders/statuses');
44+
}
3645
}
3746
})();

demo/bootstrap/server-pagination.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,21 @@
137137
<table class="table table-bordered">
138138
<thead>
139139
<tr>
140-
<th sortable="orderNo" class="sortable">Order #</th>
141-
<th sortable="datePlaced" class="sortable">Date Placed</th>
142-
<th sortable="status" class="sortable">Statuses</th>
143-
<th sortable="amount" class="sortable">Total</th>
140+
<th width="30%" sortable="orderNo" class="sortable">Order #</th>
141+
<th width="30%" sortable="datePlaced" class="sortable">Date Placed</th>
142+
<th class="st-sort-disable th-dropdown">
143+
<select class="form-control width-15"
144+
filter-by="status"
145+
filter-type="select"
146+
ng-model="status"
147+
ng-change="filter()">
148+
<option value="">All Statuses</option>
149+
<option ng-repeat="option in UI.statusOptions track by option.value"
150+
value="{{option.value}}">{{option.text}}
151+
</option>
152+
</select>
153+
</th>
154+
<th sortable="total" class="sortable">Total</th>
144155
</tr>
145156
</thead>
146157
<tbody>

src/js/dataGrid.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@
5555
}
5656
});
5757

58-
$scope.sort = function (predicate) {
59-
var direction = $scope.sortOptions.predicate === predicate && $scope.sortOptions.direction === 'desc' ? 'asc' : 'desc';
60-
$scope.sortOptions.predicate = predicate;
61-
$scope.sortOptions.direction = direction;
58+
$scope.sort = function (predicate, isDefaultSort) {
59+
if (!isDefaultSort) {
60+
var direction = $scope.sortOptions.predicate === predicate && $scope.sortOptions.direction === 'desc' ? 'asc' : 'desc';
61+
$scope.sortOptions.direction = direction;
62+
$scope.sortOptions.predicate = predicate;
63+
}
6264
$scope.paginationOptions.currentPage = 1;
6365
$scope.reloadGrid();
6466
};
@@ -217,10 +219,14 @@
217219

218220
function getData() {
219221
var url = $location.path().slice(1);
220-
$scope._gridOptions.getData('?' + url, function (data, totalItems) {
221-
$scope.filtered = data;
222-
$scope.paginationOptions.totalItems = totalItems;
223-
});
222+
if (!url && $scope.sortOptions.predicate) {
223+
$scope.sort($scope.sortOptions.predicate, true);
224+
} else {
225+
$scope._gridOptions.getData('?' + url, function (data, totalItems) {
226+
$scope.filtered = data;
227+
$scope.paginationOptions.totalItems = totalItems;
228+
});
229+
}
224230
// -> to promise
225231
//$scope._gridOptions.getData('?' + url).then(function (data, totalItems) {
226232
// $scope.filtered = data;

0 commit comments

Comments
 (0)