1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | ngTableSelectFilterDs.$inject = [];
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function ngTableSelectFilterDs() {
|
18 |
|
19 |
|
20 | var directive = {
|
21 | restrict: 'A',
|
22 | controller: NgTableSelectFilterDsController
|
23 | };
|
24 | return directive;
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | export var NgTableSelectFilterDsController = (function () {
|
30 | function NgTableSelectFilterDsController($scope, $parse, $attrs, $q) {
|
31 | var _this = this;
|
32 | this.$scope = $scope;
|
33 | this.$attrs = $attrs;
|
34 | this.$q = $q;
|
35 | this.$column = $parse($attrs.ngTableSelectFilterDs)($scope);
|
36 | $scope.$watch(function () { return _this.$column && _this.$column.data; }, function () { _this.bindDataSource(); });
|
37 | }
|
38 | NgTableSelectFilterDsController.prototype.bindDataSource = function () {
|
39 | var _this = this;
|
40 | this.getSelectListData(this.$column).then(function (data) {
|
41 | if (data && !_this.hasEmptyOption(data)) {
|
42 | data.unshift({ id: '', title: '' });
|
43 | }
|
44 | data = data || [];
|
45 | _this.$scope.$selectData = data;
|
46 | });
|
47 | };
|
48 | NgTableSelectFilterDsController.prototype.hasEmptyOption = function (data) {
|
49 | var isMatch;
|
50 | for (var i = 0; i < data.length; i++) {
|
51 | var item = data[i];
|
52 | if (item && item.id === '') {
|
53 | isMatch = true;
|
54 | break;
|
55 | }
|
56 | }
|
57 | return isMatch;
|
58 | };
|
59 | NgTableSelectFilterDsController.prototype.getSelectListData = function ($column) {
|
60 | var dataInput = $column.data;
|
61 | if (dataInput instanceof Array) {
|
62 | return this.$q.when(dataInput);
|
63 | }
|
64 | else {
|
65 | return this.$q.when(dataInput && dataInput());
|
66 | }
|
67 | };
|
68 | NgTableSelectFilterDsController.$inject = ['$scope', '$parse', '$attrs', '$q'];
|
69 | return NgTableSelectFilterDsController;
|
70 | }());
|
71 | export { ngTableSelectFilterDs };
|
72 |
|
\ | No newline at end of file |