|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset=" utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 6 | + <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 7 | + <meta name="apple-mobile-web-app-status-bar-style" content="black" /> |
| 8 | + <meta name="viewport" content="width = device-width, minimal-ui, initial-scale = 1, user-scalable = no" /> |
| 9 | + <meta name="apple-mobile-web-app-title" content="Datagrid"> |
| 10 | + <title>Datagrid - All Options</title> |
| 11 | + <base href="/"> |
| 12 | + <style> |
| 13 | + *, *:after, *:before { |
| 14 | + -webkit-box-sizing: border-box; |
| 15 | + -moz-box-sizing: border-box; |
| 16 | + box-sizing: border-box; |
| 17 | + } |
| 18 | + |
| 19 | + body{ |
| 20 | + font-family: 'RobotoDraft', 'Roboto', 'Helvetica Neue, Helvetica, Arial', sans-serif; |
| 21 | + font-style: normal; |
| 22 | + font-weight: 300; |
| 23 | + font-size: 1.4rem; |
| 24 | + line-height: 2rem; |
| 25 | + letter-spacing: 0.01rem; |
| 26 | + color: #212121; |
| 27 | + background-color: #f5f5f5; |
| 28 | + -webkit-font-smoothing: antialiased; |
| 29 | + -moz-osx-font-smoothing: grayscale; |
| 30 | + text-rendering: optimizeLegibility; |
| 31 | + } |
| 32 | + |
| 33 | + .dt{ |
| 34 | + width:75%; |
| 35 | + margin:50px auto; |
| 36 | + } |
| 37 | + |
| 38 | + </style> |
| 39 | + <link href="../dist/dataTable.css" media="all" rel="stylesheet" /> |
| 40 | + <link href="../dist/themes/material.css" media="all" rel="stylesheet" /> |
| 41 | + <link href="http://fontastic.s3.amazonaws.com/Jnf54BZCm7mSjGCxNRbfp3/icons.css" rel="stylesheet"> |
| 42 | + </head> |
| 43 | + <body ng-app="app" ng-controller="HomeController"> |
| 44 | + <button type="button" ng-click="clearData()">Clear Data</button> |
| 45 | + <button type="button" ng-click="loadData()">Load Data</button> |
| 46 | + |
| 47 | + <button type="button" ng-click="groupCountry()">Group on Country</button> |
| 48 | + <button type="button" ng-click="groupYear()">Group on Year</button> |
| 49 | + <button type="button" ng-click="groupingOff()">Grouping off</button> |
| 50 | + |
| 51 | + <label><input type="checkbox" ng-change="addRemovePaging()" ng-model="hasPaging" />Has Paging</label> |
| 52 | + <label><input type="checkbox" ng-change="addRemoveScrollbarV()" ng-model="hasScrollbarV" />Has ScrollbarV</label> |
| 53 | + <label><input type="checkbox" ng-model="showTable" />Show Table</label> |
| 54 | + |
| 55 | + <div ng-if="showTable"> |
| 56 | + <dtable options="options" rows="data" class="material" on-row-dbl-click="onRowDblClick(row)"></dtable> |
| 57 | + </div> |
| 58 | + |
| 59 | + <script src="../jspm_packages/system.js"></script> |
| 60 | + <script src="../config.js"></script> |
| 61 | + |
| 62 | + <script> |
| 63 | + |
| 64 | + System.import('dataTable').then(function(dt){ |
| 65 | + var module = angular.module('app', [ dt.default.name ]); |
| 66 | + |
| 67 | + module.controller('HomeController', function($scope, $http){ |
| 68 | + window.scope = $scope; |
| 69 | + $scope.hasPaging = false; |
| 70 | + $scope.hasScrollbarV = false; |
| 71 | + $scope.showTable = true; |
| 72 | + $scope.data = []; |
| 73 | + |
| 74 | + $scope.options = { |
| 75 | + rowHeight: 50, |
| 76 | + headerHeight: 50, |
| 77 | + footerHeight: false, |
| 78 | + scrollbarV: $scope.hasScrollbarV, // Note: this loses reference to scope variable when passed to directive |
| 79 | + selectable: false, |
| 80 | + columns: [ |
| 81 | + { name: 'Athlete', prop: 'athlete', width: 300 }, |
| 82 | + { name: 'Country', prop: 'country' }, |
| 83 | + { name: 'Year', prop: 'year' }, |
| 84 | + { name: 'Sport', prop: 'sport' } |
| 85 | + ] |
| 86 | + }; |
| 87 | + |
| 88 | + $scope.onRowDblClick = function(row) { |
| 89 | + console.log('Row Double Clicked', row); |
| 90 | + } |
| 91 | + |
| 92 | + /** Loading/Clearing data section **/ |
| 93 | + $scope.loadData = function() { |
| 94 | + $scope.data = undefined; |
| 95 | + |
| 96 | + $http.get('/demos/data/olympics.json').success(function(data) { |
| 97 | + $scope.data = data; |
| 98 | + |
| 99 | + if ($scope.hasPaging) { |
| 100 | + angular.extend($scope.options, { |
| 101 | + paging: { |
| 102 | + count: data.length |
| 103 | + } |
| 104 | + }); |
| 105 | + } |
| 106 | + }); |
| 107 | + }; |
| 108 | + |
| 109 | + $scope.clearData = function() { |
| 110 | + if ($scope.data) { |
| 111 | + $scope.data.splice(0, $scope.data.length); |
| 112 | + |
| 113 | + if ($scope.options.paging.count) { |
| 114 | + angular.extend($scope.options.paging, { |
| 115 | + count: 0 |
| 116 | + }); |
| 117 | + } |
| 118 | + } |
| 119 | + }; |
| 120 | + |
| 121 | + /** Grouping section **/ |
| 122 | + |
| 123 | + $scope.groupCountry = function() { |
| 124 | + _clearGroupColumns(); |
| 125 | + |
| 126 | + var col = $scope.options.columns.find(function(c) { |
| 127 | + return c.prop === 'country'; |
| 128 | + }); |
| 129 | + |
| 130 | + col.group = !col.group; |
| 131 | + }; |
| 132 | + |
| 133 | + $scope.groupYear = function() { |
| 134 | + _clearGroupColumns(); |
| 135 | + |
| 136 | + var col = $scope.options.columns.find(function(c) { |
| 137 | + return c.prop === 'year'; |
| 138 | + }); |
| 139 | + |
| 140 | + col.group = !col.group; |
| 141 | + }; |
| 142 | + |
| 143 | + $scope.groupingOff = function() { |
| 144 | + _clearGroupColumns(); |
| 145 | + }; |
| 146 | + |
| 147 | + function _clearGroupColumns() { |
| 148 | + $scope.options.columns.map(function(column) { |
| 149 | + if (column.group) { |
| 150 | + delete column.group; |
| 151 | + } |
| 152 | + }); |
| 153 | + }; |
| 154 | + |
| 155 | + /** Paging section **/ |
| 156 | + $scope.addRemovePaging = function() { |
| 157 | + if ($scope.hasPaging) { |
| 158 | + angular.extend($scope.options, { |
| 159 | + footerHeight: 50, |
| 160 | + paging: { |
| 161 | + size: 10, |
| 162 | + count: ($scope.data) ? $scope.data.length : 0 |
| 163 | + } |
| 164 | + }); |
| 165 | + } else { |
| 166 | + angular.extend($scope.options, { |
| 167 | + footerHeight: undefined, |
| 168 | + paging: {} |
| 169 | + }); |
| 170 | + } |
| 171 | + }; |
| 172 | + |
| 173 | + /** Scrollbar section **/ |
| 174 | + $scope.addRemoveScrollbarV = function() { |
| 175 | + if ($scope.hasScrollbarV) { |
| 176 | + angular.extend($scope.options, { |
| 177 | + scrollbarV: true |
| 178 | + }); |
| 179 | + } else { |
| 180 | + angular.extend($scope.options, { |
| 181 | + scrollbarV: false |
| 182 | + }); |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + }); |
| 187 | + }); |
| 188 | + </script> |
| 189 | + |
| 190 | + </body> |
| 191 | +</html> |
0 commit comments