-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathexample-advanced.html
350 lines (319 loc) · 16 KB
/
example-advanced.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<!DOCTYPE html>
<html>
<head>
<title>Angular Tablesort - Advanced</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="tablesort.css"/>
<style>.ng-cloak,[ng-cloak]{display:none;}</style>
</head>
<body>
<div ng-app="myApp" class="container" ng-cloak>
<div ng-controller="tableTestCtrl" >
<div class="alert alert-info">
<h4><span class="glyphicon glyphicon-info-sign"></span> About Pagination</h4>
<p>This demo page has examples that use the <a href="http://angular-ui.github.io/bootstrap/#/pagination" class="alert-link" target="_blank">Angular-UI Bootstrap pagination directive</a>, but really any pagination directive could be used here</p>
</div>
<hr />
<h2>With configured Filtering, Pagination, and Item Name</small></h2>
<table class="table table-striped" ts-wrapper ts-item-name="product">
<thead>
<tr>
<th>Select</th>
<th ts-criteria="Id" ts-filter>Id</th>
<th ts-criteria="Name|lowercase" ts-filter ts-default>Name</th>
<th ts-criteria="Price|parseFloat" ts-filter>Price</th>
<th ts-criteria="Quantity|parseInt" ts-filter>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in tableOneItems track by item.Id"
ng-class="{'active':item.Selected}"
ts-repeat>
<td><input type="checkbox" ng-model="item.Selected" /></td>
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
<hr />
<h2>Custom Filtering UI, filter function, & "no data" message</small></h2>
<div class="row">
<div class="col-xs-6 col-sm-4 col-sm-offset-4 col-md-3 col-md-offset-6">
<div class="form-group has-feedback">
<label for="cstm-filter-name" class="control-label">Name</label>
<input type="search" id="cstm-filter-name" class="form-control" ng-model="customNameFilter" />
<span class='glyphicon glyphicon-search form-control-feedback' aria-hidden='true'></span>
</div>
</div>
<div class="col-xs-6 col-sm-4 col-md-3">
<div class="form-group">
<label for="cstm-filter-price" class="control-label">Price</label>
<select id="cstm-filter-price" class="form-control" ng-model="customPriceFilter">
<option value="">All</option>
<option value="under20">Under $20</option>
<option value="20to50">Between $20 and $50</option>
<option value="over50">Over $50</option>
</select>
</div>
</div>
</div>
<table class="table table-striped" ts-wrapper ts-display-filtering="false" ts-filter-function="customFilterFn" ts-no-data-text="Nothing to see here!">
<thead>
<tr>
<th>Select</th>
<th ts-criteria="Id" ts-filter>Id</th>
<th ts-criteria="Name|lowercase" ts-filter ts-default>Name</th>
<th ts-criteria="Price|parseFloat" ts-filter>Price</th>
<th ts-criteria="Quantity|parseInt" ts-filter>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in tableTwoItems track by item.Id"
ng-class="{'active':item.Selected}"
ts-repeat>
<td><input type="checkbox" ng-model="item.Selected" /></td>
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
<hr />
<h2>Disabled filtering & paging</h2>
<table class="table table-striped" ts-wrapper ts-display-filtering="false" ts-display-pagination="false">
<thead>
<tr>
<th>Select</th>
<th ts-criteria="Id" ts-filter ts-default>Id</th>
<th ts-criteria="Name|lowercase" ts-filter>Name</th>
<th ts-criteria="Price|parseFloat" ts-filter>Price</th>
<th ts-criteria="Quantity|parseInt" ts-filter>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in tableThreeItems track by item.Id"
ng-class="{'active':item.Selected}"
ts-repeat>
<td><input type="checkbox" ng-model="item.Selected" /></td>
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
<hr />
<h2>Different per-page options</h2>
<table class="table table-striped" ts-wrapper ts-per-page-options="customPerPageOptions" ts-per-page-default="customPerPageDefault">
<thead>
<tr>
<th>Select</th>
<th ts-criteria="Id" ts-filter>Id</th>
<th ts-criteria="Name|lowercase" ts-filter ts-default>Name</th>
<th ts-criteria="Price|parseFloat" ts-filter>Price</th>
<th ts-criteria="Quantity|parseInt" ts-filter>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in tableFourItems track by item.Id"
ng-class="{'active':item.Selected}"
ts-repeat>
<td><input type="checkbox" ng-model="item.Selected" /></td>
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
<hr />
<h2>With special event names and no pagination (see console for events)</small></h2>
<table class="table table-striped" ts-wrapper>
<thead>
<tr>
<th ts-criteria="Id" ts-name="id">Id</th>
<th ts-criteria="Name|lowercase" ts-name="name" ts-default>Name</th>
<th ts-criteria="Price|parseFloat" ts-name="price">Price</th>
<th ts-criteria="Quantity|parseInt" ts-name="quantity">Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in tableFiveItems track by item.Id"
ts-repeat>
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
<hr />
<h2>Custom table layout without a header</h2>
<table class="table table-striped" ts-wrapper ts-item-name="product" ts-filter-fields="Name">
<tbody>
<tr ng-repeat="item in tableOneItems track by item.Id"
ts-repeat>
<td>
<div>
<label>Name</label> <input type="text" class="form-control" ng-model="item.Name" />
</div>
</td>
<td>
<div>
<label>Id</label> {{item.Id}}
</div>
<div>
<label>Price</label> {{item.Price | currency}}
</div>
<div>
<label>Qty</label> {{item.Quantity}}
</div>
</td>
</tr>
</tbody>
</table>
<hr />
<h2>Get Table Data</h2>
<button type="button" class="btn btn-primary" ng-click="getTableData(getDataFn)">Log Table Data To Console</button>
<label class="checkbox-inline">
<input type="checkbox" ng-model="shouldApplySorting">
Apply Sorting
</label>
<label class="checkbox-inline">
<input type="checkbox" ng-model="shouldApplyFiltering">
Apply Filtering
</label>
<label class="checkbox-inline">
<input type="checkbox" ng-model="limitToCurrentPageOnly">
Current page only
</label>
<table class="table table-striped" ts-wrapper ts-item-name="product" ts-get-table-data-function="getDataFn">
<thead>
<tr>
<th>Select</th>
<th ts-criteria="Id" ts-filter>Id</th>
<th ts-criteria="Name|lowercase" ts-filter ts-default>Name</th>
<th ts-criteria="Price|parseFloat" ts-filter>Price</th>
<th ts-criteria="Quantity|parseInt" ts-filter>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in tableSixItems track by item.Id"
ng-class="{'active':item.Selected}"
ts-repeat>
<td><input type="checkbox" ng-model="item.Selected" /></td>
<td>{{item.Id}}</td>
<td>{{item.Name}}</td>
<td>{{item.Price | currency}}</td>
<td>{{item.Quantity}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.3.2/ui-bootstrap-tpls.min.js"></script>
<script src="js/angular-tablesort.js"></script>
<script>
function getFakeData(count){
var items = [];
var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function getRandLetter(){
return charset.charAt(Math.floor(Math.random() * charset.length));
}
for(var i = 0; i < count; i++){
var idStr = (i < 10 ? "0" + i : i).toString();
var nameStr = getRandLetter() + getRandLetter() + getRandLetter();
var priceStr = (Math.random()*100).toFixed(2);
var qty = Math.floor(Math.random() * (25 - 1 + 1) + 1);
items.push({
Id: idStr,
Name: nameStr,
Price: priceStr,
Quantity: qty,
selected: false
});
}
return items;
}
angular
.module( 'myApp', ['tableSort', 'ui.bootstrap'] )
.controller( "tableTestCtrl", function tableTestCtrl($scope) {
$scope.$on('tablesort:sortOrder', (event, sortOrder) => {
console.log('tablesort:sortOrder event', sortOrder);
});
//Generate some fake data
$scope.tableOneItems = getFakeData(100);
$scope.tableTwoItems = getFakeData(100);
$scope.tableThreeItems = getFakeData(12);
$scope.tableFourItems = getFakeData(100);
$scope.tableFiveItems = getFakeData(20);
$scope.tableSixItems = getFakeData(25);
$scope.customPerPageOptions = [20,40,60];
$scope.customPerPageDefault = 40;
//Custom filter stuff (tableTwoItems)
$scope.customNameFilter = "";
$scope.customPriceFilter = "";
$scope.customFilterFn = function(item) {
var nameMatch = item.Name.toLowerCase().indexOf($scope.customNameFilter.toLowerCase()) > -1;
var priceMatch = true;
if($scope.customPriceFilter==="under20"){
priceMatch = item.Price < 20;
}else if($scope.customPriceFilter==="20to50"){
priceMatch = item.Price >= 20 && item.Price <= 50;
} else if($scope.customPriceFilter==="over50"){
priceMatch = item.Price > 50;
}
return nameMatch && priceMatch;
};
//Get Table Data
$scope.shouldApplySorting = true;
$scope.shouldApplyFiltering = true;
$scope.limitToCurrentPageOnly = false;
$scope.getTableData = function (getDataFn) {
var results = getDataFn($scope.shouldApplySorting, $scope.shouldApplyFiltering, $scope.limitToCurrentPageOnly);
console.log("data from table", results)
};
});
angular
.module('myApp')
.config(['tableSortConfigProvider', function(tableSortConfigProvider){
//Globally configured filtering & pagination templates
/* Template Tokens - all are replaced by Angular expressions
* TOTAL_COUNT - The number for the total count of items in the table
* FILTERED_COUNT - The number for the total count of items in the table after the filter has been applied
* FILTER_STRING - The string used for the `ng-model` of the text filter
* PER_PAGE_OPTIONS - The array of numbers for the verious page size options
* ITEMS_PER_PAGE - The number for the selected number of items to display per page (the selected item from PER_PAGE_OPTIONS)
* CURRENT_PAGE_NUMBER - The number for the page that is currently being viewed
* CURRENT_PAGE_RANGE - The number for the current viewable range of pages
* ITEM_NAME_SINGULAR - The singular version of the name of the items being iterated over
* ITEM_NAME_PLURAL - The plural version of the name of the items being iterated over
*/
var filterString = "<div class='row'>";
filterString += "<div class='col-sm-4 col-md-3 col-sm-offset-8 col-md-offset-9'>";
filterString += "<div class='form-group has-feedback'>";
filterString += "<input type='search' class='form-control' placeholder='filter {{ITEM_NAME_PLURAL}}' ng-model='FILTER_STRING'/>";
filterString += "<span class='glyphicon glyphicon-search form-control-feedback' aria-hidden='true'></span>";
filterString += "</div>";
filterString += "</div>";
filterString += "</div>";
tableSortConfigProvider.filterTemplate = filterString;
var pagerString = "<div class='text-right'>";
pagerString += "<small class='text-muted'>Showing {{CURRENT_PAGE_RANGE}} {{FILTERED_COUNT === 0 ? '' : 'of'}} ";
pagerString += "<span ng-if='FILTERED_COUNT === TOTAL_COUNT'>{{TOTAL_COUNT | number}} {{TOTAL_COUNT === 1 ? ITEM_NAME_SINGULAR : ITEM_NAME_PLURAL}}</span>";
pagerString += "<span ng-if='FILTERED_COUNT !== TOTAL_COUNT'>{{FILTERED_COUNT | number}} {{FILTERED_COUNT === 1 ? ITEM_NAME_SINGULAR : ITEM_NAME_PLURAL}} (filtered from {{TOTAL_COUNT | number}})</span>";
pagerString += "</small> ";
pagerString += "<uib-pagination style='vertical-align:top; margin-top:0;' ng-if='ITEMS_PER_PAGE < TOTAL_COUNT' ng-model='CURRENT_PAGE_NUMBER' total-items='FILTERED_COUNT' items-per-page='ITEMS_PER_PAGE' max-size='5' force-ellipses='true'></uib-pagination>";
pagerString += " ";
pagerString += "<div class='form-group' style='display:inline-block;'><select class='form-control' ng-model='ITEMS_PER_PAGE' ng-options='opt as (opt + \" per page\") for opt in PER_PAGE_OPTIONS'></select></div>";
pagerString += "</div>";
tableSortConfigProvider.paginationTemplate = pagerString;
}
]);
</script>
</body>
</html>