1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import * as ng1 from 'angular';
|
9 | ngTableDynamic.$inject = [];
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export function ngTableDynamic() {
|
25 | return {
|
26 | restrict: 'A',
|
27 | priority: 1001,
|
28 | scope: true,
|
29 | controller: 'ngTableController',
|
30 | compile: function (tElement) {
|
31 | var row;
|
32 |
|
33 | ng1.forEach(tElement.find('tr'), function (tr) {
|
34 | tr = ng1.element(tr);
|
35 | if (!tr.hasClass('ng-table-group') && !row) {
|
36 | row = tr;
|
37 | }
|
38 | });
|
39 | if (!row) {
|
40 | return undefined;
|
41 | }
|
42 | ng1.forEach(row.find('td'), function (item) {
|
43 | var el = ng1.element(item);
|
44 | var getAttrValue = function (attr) {
|
45 | return el.attr('x-data-' + attr) || el.attr('data-' + attr) || el.attr(attr);
|
46 | };
|
47 |
|
48 | var titleExpr = getAttrValue('title');
|
49 | if (!titleExpr) {
|
50 | el.attr('data-title-text', '{{$columns[$index].titleAlt(this) || $columns[$index].title(this)}}');
|
51 | }
|
52 | var showExpr = el.attr('ng-if');
|
53 | if (!showExpr) {
|
54 | el.attr('ng-if', '$columns[$index].show(this)');
|
55 | }
|
56 | });
|
57 | return function (scope, element, attrs, controller) {
|
58 | var expr = controller.parseNgTableDynamicExpr(attrs.ngTableDynamic);
|
59 | controller.setupBindingsToInternalScope(expr.tableParams);
|
60 | controller.compileDirectiveTemplates();
|
61 | scope.$watchCollection(expr.columns, function (newCols /*, oldCols*/) {
|
62 | scope.$columns = controller.buildColumns(newCols);
|
63 | controller.loadFilterData(scope.$columns);
|
64 | });
|
65 | };
|
66 | }
|
67 | };
|
68 | }
|
69 |
|
\ | No newline at end of file |