From b1680060b7d853896ca41941f4c2d743d1c29ba0 Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Thu, 28 Jul 2016 11:26:22 -0400 Subject: [PATCH 1/7] readme typo - include options # --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7fbe4cc..dc2d9bc 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ docs coming soon, in the meantime, 'View Source' is your friend ;)! #### Include -You've got 5 different options to include this in your build depending on your setup. +You've got 4 different options to include this in your build depending on your setup. - `./release/dataTable.js` - A standalone file that was compiled with Babel (UMD) - `./release/dataTable.min.js` - A minified standalone file that was compiled with Babel (UMD) - `./release/dataTable.cjs.js` - A standalone file that was compiled with Babel (CommonJS) - `./release/dataTable.es6.js` - Raw ES6 Version. - + All distributions include babel helpers, so they do not have to be included separately. There is also the CSS too: From 6ad004aecfbce8795b28dc80862df406377fdc8f Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Tue, 16 Aug 2016 14:29:17 -0400 Subject: [PATCH 2/7] changes to determine --- src/components/DataTableController.js | 4 ++-- src/components/DataTableDirective.js | 3 ++- src/components/header/HeaderCellController.js | 7 ++++--- src/components/header/HeaderCellDirective.js | 9 ++++++--- src/components/header/HeaderController.js | 1 + src/components/header/HeaderDirective.js | 4 ++++ 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/DataTableController.js b/src/components/DataTableController.js index d0a0e64..27ef58d 100644 --- a/src/components/DataTableController.js +++ b/src/components/DataTableController.js @@ -243,8 +243,8 @@ export class DataTableController { * @return {Boolean} if all selected */ isAllRowsSelected(){ - if(this.rows) return false; - return this.selected.length === this.rows.length; + console.log(this.selected.length, ((this.rows) ? this.rows.length : null), (!this.rows) ? false : this.selected.length === this.rows.length); + return (!this.rows) ? false : this.selected.length === this.rows.length; } /** diff --git a/src/components/DataTableDirective.js b/src/components/DataTableDirective.js index 521c303..dc291f9 100644 --- a/src/components/DataTableDirective.js +++ b/src/components/DataTableDirective.js @@ -38,7 +38,8 @@ export function DataTableDirective($window, $timeout, $parse){ column-widths="dt.columnWidths" ng-if="dt.options.headerHeight" on-resize="dt.onResized(column, width)" - selected="dt.isAllRowsSelected()" + is-all-rows-selected="dt.isAllRowsSelected()" + selected-rows="dt.selected" on-sort="dt.onSorted()"> diff --git a/src/components/header/HeaderController.js b/src/components/header/HeaderController.js index 36ea34b..015356f 100644 --- a/src/components/header/HeaderController.js +++ b/src/components/header/HeaderController.js @@ -76,6 +76,7 @@ export class HeaderController { * @param {scope} */ onCheckboxChanged(){ + console.log('HeaderController.onCheckboxChanged', this); this.onCheckboxChange(); } diff --git a/src/components/header/HeaderDirective.js b/src/components/header/HeaderDirective.js index c7ea0ab..d79d3bd 100644 --- a/src/components/header/HeaderDirective.js +++ b/src/components/header/HeaderDirective.js @@ -11,6 +11,8 @@ export function HeaderDirective($timeout){ options: '=', columns: '=', columnWidths: '=', + isAllRowsSelected: '=', + selectedRows: '=?', onSort: '&', onResize: '&', onCheckboxChange: '&' @@ -32,6 +34,8 @@ export function HeaderDirective($timeout){ sort-type="header.options.sortType" on-resize="header.onResized(column, width)" selected="header.isSelected()" + is-all-rows-selected="header.isAllRowsSelected" + selected-rows="header.selectedRows" column="column"> From 4bf3b5ea16a515f140c7155340d385d4405c6a35 Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Sun, 23 Oct 2016 10:18:47 -0400 Subject: [PATCH 3/7] upgrading various packages including angular to 1.5.0 to take advantage of lifecycle hooks --- config.js | 74 +++++++++++++++++++++++++++++++++++++++++++--------- package.json | 18 ++++++++----- 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/config.js b/config.js index 961df0f..d0eba4b 100644 --- a/config.js +++ b/config.js @@ -14,23 +14,71 @@ System.config({ }, map: { - "angular": "npm:angular@1.4.0", - "babel": "npm:babel-core@5.8.22", - "babel-runtime": "npm:babel-runtime@5.8.20", - "core-js": "npm:core-js@1.1.1", - "github:jspm/nodelibs-process@0.1.1": { - "process": "npm:process@0.10.1" + "angular": "npm:angular@1.5.0", + "babel": "npm:babel-core@5.8.38", + "babel-runtime": "npm:babel-runtime@5.8.38", + "core-js": "npm:core-js@1.2.7", + "github:jspm/nodelibs-assert@0.1.0": { + "assert": "npm:assert@1.4.1" }, - "npm:angular@1.4.0": { - "process": "github:jspm/nodelibs-process@0.1.1" + "github:jspm/nodelibs-buffer@0.1.0": { + "buffer": "npm:buffer@3.6.0" }, - "npm:babel-runtime@5.8.20": { - "process": "github:jspm/nodelibs-process@0.1.1" + "github:jspm/nodelibs-path@0.1.0": { + "path-browserify": "npm:path-browserify@0.0.0" }, - "npm:core-js@1.1.1": { + "github:jspm/nodelibs-process@0.1.2": { + "process": "npm:process@0.11.9" + }, + "github:jspm/nodelibs-util@0.1.0": { + "util": "npm:util@0.10.3" + }, + "github:jspm/nodelibs-vm@0.1.0": { + "vm-browserify": "npm:vm-browserify@0.0.4" + }, + "npm:angular@1.5.0": { + "process": "github:jspm/nodelibs-process@0.1.2" + }, + "npm:assert@1.4.1": { + "assert": "github:jspm/nodelibs-assert@0.1.0", + "buffer": "github:jspm/nodelibs-buffer@0.1.0", + "process": "github:jspm/nodelibs-process@0.1.2", + "util": "npm:util@0.10.3" + }, + "npm:babel-runtime@5.8.38": { + "process": "github:jspm/nodelibs-process@0.1.2" + }, + "npm:buffer@3.6.0": { + "base64-js": "npm:base64-js@0.0.8", + "child_process": "github:jspm/nodelibs-child_process@0.1.0", + "fs": "github:jspm/nodelibs-fs@0.1.2", + "ieee754": "npm:ieee754@1.1.8", + "isarray": "npm:isarray@1.0.0", + "process": "github:jspm/nodelibs-process@0.1.2" + }, + "npm:core-js@1.2.7": { "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.1", - "systemjs-json": "github:systemjs/plugin-json@0.1.0" + "path": "github:jspm/nodelibs-path@0.1.0", + "process": "github:jspm/nodelibs-process@0.1.2", + "systemjs-json": "github:systemjs/plugin-json@0.1.2" + }, + "npm:inherits@2.0.1": { + "util": "github:jspm/nodelibs-util@0.1.0" + }, + "npm:path-browserify@0.0.0": { + "process": "github:jspm/nodelibs-process@0.1.2" + }, + "npm:process@0.11.9": { + "assert": "github:jspm/nodelibs-assert@0.1.0", + "fs": "github:jspm/nodelibs-fs@0.1.2", + "vm": "github:jspm/nodelibs-vm@0.1.0" + }, + "npm:util@0.10.3": { + "inherits": "npm:inherits@2.0.1", + "process": "github:jspm/nodelibs-process@0.1.2" + }, + "npm:vm-browserify@0.0.4": { + "indexof": "npm:indexof@0.0.1" } } }); diff --git a/package.json b/package.json index 9597fd5..4a6a297 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,13 @@ "url": "http://opensource.org/licenses/mit-license.php" } ], + "scripts": { + "start": "node ./node_modules/gulp/bin/gulp.js watch serve", + "release": "node ./node_modules/gulp/bin/gulp.js release" + }, "devDependencies": { - "angular": "^1.4.4", - "angular-mocks": "^1.4.3", - "babelify": "7.3.0", + "angular": "^1.5.0", + "angular-mocks": "^1.5.0", "babel-core": "^6.9.0", "babel-eslint": "^6.0.2", "babel-plugin-external-helpers": "^6.5.0", @@ -33,6 +36,7 @@ "babel-plugin-transform-es2015-modules-umd": "^6.8.0", "babel-preset-es2015": "^6.9.0", "babel-preset-stage-0": "^6.5.0", + "babelify": "7.3.0", "browser-sync": "^2.7.2", "chai-as-promised": "^5.3.0", "del": "^1.2.0", @@ -68,12 +72,12 @@ }, "jspm": { "dependencies": { - "angular": "npm:angular@^1.4.0" + "angular": "npm:angular@^1.5.0" }, "devDependencies": { - "babel": "npm:babel-core@^5.8.22", - "babel-runtime": "npm:babel-runtime@^5.6.4", - "core-js": "npm:core-js@^1.1.1" + "babel": "npm:babel-core@^5.8.24", + "babel-runtime": "npm:babel-runtime@^5.8.24", + "core-js": "npm:core-js@^1.1.4" } }, "babel": { From f46e7ba9b846b2d2f99e50de042108c43b872c36 Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Sun, 23 Oct 2016 13:09:06 -0400 Subject: [PATCH 4/7] fixed header out-of-sync issues --- config.js | 41 +++++++++++++++++++ package.json | 16 +++++++- src/components/DataTableController.js | 39 +++++++++++------- src/components/DataTableDirective.js | 3 +- src/components/header/HeaderCellController.js | 21 ++++++++-- src/components/header/HeaderCellDirective.js | 10 ++--- src/components/header/HeaderController.js | 11 ----- src/components/header/HeaderDirective.js | 11 ++--- 8 files changed, 105 insertions(+), 47 deletions(-) diff --git a/config.js b/config.js index d0eba4b..03435bc 100644 --- a/config.js +++ b/config.js @@ -18,6 +18,8 @@ System.config({ "babel": "npm:babel-core@5.8.38", "babel-runtime": "npm:babel-runtime@5.8.38", "core-js": "npm:core-js@1.2.7", + "lodash": "npm:lodash@4.16.4", + "ui-utils-npm": "npm:ui-utils-npm@1.0.0", "github:jspm/nodelibs-assert@0.1.0": { "assert": "npm:assert@1.4.1" }, @@ -36,6 +38,36 @@ System.config({ "github:jspm/nodelibs-vm@0.1.0": { "vm-browserify": "npm:vm-browserify@0.0.4" }, + "npm:angular-ui-event@1.0.0": { + "fs": "github:jspm/nodelibs-fs@0.1.2" + }, + "npm:angular-ui-indeterminate@1.0.0": { + "fs": "github:jspm/nodelibs-fs@0.1.2" + }, + "npm:angular-ui-mask@1.8.7": { + "fs": "github:jspm/nodelibs-fs@0.1.2", + "process": "github:jspm/nodelibs-process@0.1.2", + "systemjs-json": "github:systemjs/plugin-json@0.1.2" + }, + "npm:angular-ui-scroll@1.5.1": { + "buffer": "github:jspm/nodelibs-buffer@0.1.0", + "process": "github:jspm/nodelibs-process@0.1.2" + }, + "npm:angular-ui-scrollpoint@2.1.1": { + "fs": "github:jspm/nodelibs-fs@0.1.2", + "process": "github:jspm/nodelibs-process@0.1.2", + "systemjs-json": "github:systemjs/plugin-json@0.1.2" + }, + "npm:angular-ui-uploader@1.2.1": { + "fs": "github:jspm/nodelibs-fs@0.1.2", + "process": "github:jspm/nodelibs-process@0.1.2", + "systemjs-json": "github:systemjs/plugin-json@0.1.2" + }, + "npm:angular-ui-validate@1.2.2": { + "fs": "github:jspm/nodelibs-fs@0.1.2", + "process": "github:jspm/nodelibs-process@0.1.2", + "systemjs-json": "github:systemjs/plugin-json@0.1.2" + }, "npm:angular@1.5.0": { "process": "github:jspm/nodelibs-process@0.1.2" }, @@ -73,6 +105,15 @@ System.config({ "fs": "github:jspm/nodelibs-fs@0.1.2", "vm": "github:jspm/nodelibs-vm@0.1.0" }, + "npm:ui-utils-npm@1.0.0": { + "angular-ui-event": "npm:angular-ui-event@1.0.0", + "angular-ui-indeterminate": "npm:angular-ui-indeterminate@1.0.0", + "angular-ui-mask": "npm:angular-ui-mask@1.8.7", + "angular-ui-scroll": "npm:angular-ui-scroll@1.5.1", + "angular-ui-scrollpoint": "npm:angular-ui-scrollpoint@2.1.1", + "angular-ui-uploader": "npm:angular-ui-uploader@1.2.1", + "angular-ui-validate": "npm:angular-ui-validate@1.2.2" + }, "npm:util@0.10.3": { "inherits": "npm:inherits@2.0.1", "process": "github:jspm/nodelibs-process@0.1.2" diff --git a/package.json b/package.json index 4a6a297..e53ec41 100644 --- a/package.json +++ b/package.json @@ -25,12 +25,21 @@ "start": "node ./node_modules/gulp/bin/gulp.js watch serve", "release": "node ./node_modules/gulp/bin/gulp.js release" }, + "dependencies": { + "lodash": "^4.16.4", + "ui-utils-npm": "^1.0.0" + }, + "peerDependencies": { + "angular": "1.5.x" + }, "devDependencies": { "angular": "^1.5.0", "angular-mocks": "^1.5.0", + "babel-cli": "^6.16.0", "babel-core": "^6.9.0", "babel-eslint": "^6.0.2", "babel-plugin-external-helpers": "^6.5.0", + "babel-plugin-lodash": "^3.2.9", "babel-plugin-transform-es2015-modules-amd": "^6.8.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.8.0", "babel-plugin-transform-es2015-modules-umd": "^6.8.0", @@ -72,7 +81,9 @@ }, "jspm": { "dependencies": { - "angular": "npm:angular@^1.5.0" + "angular": "npm:angular@^1.5.0", + "lodash": "npm:lodash@^4.16.4", + "ui-utils-npm": "npm:ui-utils-npm@^1.0.0" }, "devDependencies": { "babel": "npm:babel-core@^5.8.24", @@ -82,6 +93,9 @@ }, "babel": { "sourceMaps": false, + "plugins": [ + "lodash" + ], "presets": [ "es2015", "stage-0" diff --git a/src/components/DataTableController.js b/src/components/DataTableController.js index 3f4f3f2..935ee1a 100644 --- a/src/components/DataTableController.js +++ b/src/components/DataTableController.js @@ -1,4 +1,5 @@ import angular from 'angular'; +import _ from 'lodash'; import { TableDefaults, ColumnDefaults } from '../defaults'; import { AdjustColumnWidths, ForceFillColumnWidths } from '../utils/math'; import { ColumnsByPin, ColumnGroupWidths, CamelCase, ObjectId, ScrollbarWidth } from '../utils/utils'; @@ -11,7 +12,7 @@ export class DataTableController { * @param {filter} */ /*@ngInject*/ - constructor($scope, $filter, $log, $transclude){ + constructor($scope, $filter, $log, $transclude, $window){$window.dt = this; Object.assign(this, { $scope: $scope, $filter: $filter, @@ -59,6 +60,16 @@ export class DataTableController { if(this.options.selectable && this.options.multiSelect){ this.selected = this.selected || []; + + this.$scope.$watch('dt.selected', (newVal, oldVal) => { + _.forEach(this.options.columns, (column) => { + if (column.headerCheckbox && _.isFunction(column.headerCheckboxCallback)) { + column.headerCheckboxCallback(this); + } + }); + }, true); + + console.log(this.$scope, this.selected); } } @@ -228,18 +239,18 @@ export class DataTableController { this.options.internal.setYOffset(offsetY); } - /** - * Invoked when the header checkbox directive has changed. - */ - onHeaderCheckboxChange(){ - if(this.rows){ - var matches = this.selected.length === this.rows.length; - this.selected.splice(0, this.selected.length); + selectAllRows(){ + this.selected.splice(0, this.selected.length); - if(!matches){ - this.selected.push(...this.rows); - } - } + this.selected.push(...this.rows); + + return this.isAllRowsSelected(); + } + + deselectAllRows(){ + this.selected.splice(0, this.selected.length); + + return this.isAllRowsSelected(); } /** @@ -247,8 +258,7 @@ export class DataTableController { * @return {Boolean} if all selected */ isAllRowsSelected(){ - console.log(this.selected.length, ((this.rows) ? this.rows.length : null), (!this.rows) ? false : this.selected.length === this.rows.length); - return (!this.rows) ? false : this.selected.length === this.rows.length; + return (!this.rows || !this.selected) ? false : this.selected.length === this.rows.length; } /** @@ -304,5 +314,4 @@ export class DataTableController { row: row }); } - } diff --git a/src/components/DataTableDirective.js b/src/components/DataTableDirective.js index dc291f9..3511de1 100644 --- a/src/components/DataTableDirective.js +++ b/src/components/DataTableDirective.js @@ -33,13 +33,12 @@ export function DataTableDirective($window, $timeout, $parse){ return `
-
From 4ddf2c77751cbcec5438a118df9619598d68fb77 Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Sun, 23 Oct 2016 13:56:07 -0400 Subject: [PATCH 5/7] -console log --- src/components/DataTableController.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/DataTableController.js b/src/components/DataTableController.js index 935ee1a..6a1a8d6 100644 --- a/src/components/DataTableController.js +++ b/src/components/DataTableController.js @@ -68,8 +68,6 @@ export class DataTableController { } }); }, true); - - console.log(this.$scope, this.selected); } } From 535e96ca27005cc9b6692e9b3b80174ed2570264 Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Sun, 23 Oct 2016 14:19:21 -0400 Subject: [PATCH 6/7] removed dependencies, updated version number, built release --- config.js | 42 +------------ package.json | 14 +---- release/dataTable.cjs.js | 83 ++++++++++++++++--------- release/dataTable.es6.js | 88 +++++++++++++++------------ release/dataTable.js | 83 ++++++++++++++++--------- release/dataTable.min.js | 6 +- src/components/DataTableController.js | 5 +- 7 files changed, 163 insertions(+), 158 deletions(-) diff --git a/config.js b/config.js index 03435bc..a60c69a 100644 --- a/config.js +++ b/config.js @@ -18,8 +18,7 @@ System.config({ "babel": "npm:babel-core@5.8.38", "babel-runtime": "npm:babel-runtime@5.8.38", "core-js": "npm:core-js@1.2.7", - "lodash": "npm:lodash@4.16.4", - "ui-utils-npm": "npm:ui-utils-npm@1.0.0", + "lodash-es": "npm:lodash-es@4.16.4", "github:jspm/nodelibs-assert@0.1.0": { "assert": "npm:assert@1.4.1" }, @@ -38,36 +37,6 @@ System.config({ "github:jspm/nodelibs-vm@0.1.0": { "vm-browserify": "npm:vm-browserify@0.0.4" }, - "npm:angular-ui-event@1.0.0": { - "fs": "github:jspm/nodelibs-fs@0.1.2" - }, - "npm:angular-ui-indeterminate@1.0.0": { - "fs": "github:jspm/nodelibs-fs@0.1.2" - }, - "npm:angular-ui-mask@1.8.7": { - "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.2", - "systemjs-json": "github:systemjs/plugin-json@0.1.2" - }, - "npm:angular-ui-scroll@1.5.1": { - "buffer": "github:jspm/nodelibs-buffer@0.1.0", - "process": "github:jspm/nodelibs-process@0.1.2" - }, - "npm:angular-ui-scrollpoint@2.1.1": { - "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.2", - "systemjs-json": "github:systemjs/plugin-json@0.1.2" - }, - "npm:angular-ui-uploader@1.2.1": { - "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.2", - "systemjs-json": "github:systemjs/plugin-json@0.1.2" - }, - "npm:angular-ui-validate@1.2.2": { - "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.2", - "systemjs-json": "github:systemjs/plugin-json@0.1.2" - }, "npm:angular@1.5.0": { "process": "github:jspm/nodelibs-process@0.1.2" }, @@ -105,15 +74,6 @@ System.config({ "fs": "github:jspm/nodelibs-fs@0.1.2", "vm": "github:jspm/nodelibs-vm@0.1.0" }, - "npm:ui-utils-npm@1.0.0": { - "angular-ui-event": "npm:angular-ui-event@1.0.0", - "angular-ui-indeterminate": "npm:angular-ui-indeterminate@1.0.0", - "angular-ui-mask": "npm:angular-ui-mask@1.8.7", - "angular-ui-scroll": "npm:angular-ui-scroll@1.5.1", - "angular-ui-scrollpoint": "npm:angular-ui-scrollpoint@2.1.1", - "angular-ui-uploader": "npm:angular-ui-uploader@1.2.1", - "angular-ui-validate": "npm:angular-ui-validate@1.2.2" - }, "npm:util@0.10.3": { "inherits": "npm:inherits@2.0.1", "process": "github:jspm/nodelibs-process@0.1.2" diff --git a/package.json b/package.json index e53ec41..7e86177 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "angular-data-table", "title": "AngularJS Data-Table", "description": "A feature-rich but lightweight ES6 AngularJS Data Table crafted for large data sets!", - "version": "0.6.0", + "version": "0.6.1", "repository": { "type": "git", "url": "git@github.com:Swimlane/angular-data-table.git", @@ -25,10 +25,6 @@ "start": "node ./node_modules/gulp/bin/gulp.js watch serve", "release": "node ./node_modules/gulp/bin/gulp.js release" }, - "dependencies": { - "lodash": "^4.16.4", - "ui-utils-npm": "^1.0.0" - }, "peerDependencies": { "angular": "1.5.x" }, @@ -39,7 +35,6 @@ "babel-core": "^6.9.0", "babel-eslint": "^6.0.2", "babel-plugin-external-helpers": "^6.5.0", - "babel-plugin-lodash": "^3.2.9", "babel-plugin-transform-es2015-modules-amd": "^6.8.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.8.0", "babel-plugin-transform-es2015-modules-umd": "^6.8.0", @@ -81,9 +76,7 @@ }, "jspm": { "dependencies": { - "angular": "npm:angular@^1.5.0", - "lodash": "npm:lodash@^4.16.4", - "ui-utils-npm": "npm:ui-utils-npm@^1.0.0" + "angular": "npm:angular@^1.5.0" }, "devDependencies": { "babel": "npm:babel-core@^5.8.24", @@ -93,9 +86,6 @@ }, "babel": { "sourceMaps": false, - "plugins": [ - "lodash" - ], "presets": [ "es2015", "stage-0" diff --git a/release/dataTable.cjs.js b/release/dataTable.cjs.js index f77c5e4..d0141cc 100644 --- a/release/dataTable.cjs.js +++ b/release/dataTable.cjs.js @@ -1,6 +1,6 @@ /** * angular-data-table - A feature-rich but lightweight ES6 AngularJS Data Table crafted for large data sets! - * @version v0.6.0 + * @version v0.6.1 * @link http://swimlane.com/ * @license */ @@ -1266,8 +1266,19 @@ function NextSortDirection(sortType, currentSort) { } var HeaderCellController = function () { - function HeaderCellController() { + HeaderCellController.$inject = ["$scope"]; + function HeaderCellController($scope) { _classCallCheck(this, HeaderCellController); + + this.$scope = $scope; + + if (this.$scope.$parent.$parent.$parent.$parent.dt) { + this.dt = this.$scope.$parent.$parent.$parent.$parent.dt; + } + + if (this.column.headerCheckbox) { + this.column.headerCheckboxCallback = this.rowSelected; + } } _createClass(HeaderCellController, [{ @@ -1327,9 +1338,14 @@ var HeaderCellController = function () { }); } }, { - key: "onCheckboxChange", - value: function onCheckboxChange() { - this.onCheckboxChanged(); + key: "rowSelected", + value: function rowSelected(dt) { + this.allRowsSelected = dt.selected && dt.rows.length === dt.selected.length; + } + }, { + key: "checkboxChangeCallback", + value: function checkboxChangeCallback() { + return this.isAllRowsSelected = this.column.allRowsSelected ? this.dt.selectAllRows() : this.dt.deselectAllRows(); } }]); @@ -1345,14 +1361,13 @@ function HeaderCellDirective($compile) { bindToController: { options: '=', column: '=', - onCheckboxChange: '&', onSort: '&', sortType: '=', onResize: '&', selected: '=' }, replace: true, - template: "
\n
\n \n \n \n \n
\n
", + template: "
\n
\n \n \n \n \n
\n
", compile: function compile() { return { pre: function pre($scope, $elm, $attrs, ctrl) { @@ -1438,11 +1453,6 @@ var HeaderController = function () { return styles; } - }, { - key: "onCheckboxChanged", - value: function onCheckboxChanged() { - this.onCheckboxChange(); - } }, { key: "onResized", value: function onResized(column, width) { @@ -1466,11 +1476,12 @@ function HeaderDirective($timeout) { options: '=', columns: '=', columnWidths: '=', + selectedRows: '=?', + allRows: '=', onSort: '&', - onResize: '&', - onCheckboxChange: '&' + onResize: '&' }, - template: "\n
\n\n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n
", + template: "\n
\n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n
", replace: true, link: function link($scope, $elm, $attrs, ctrl) { @@ -2019,12 +2030,13 @@ var TableDefaults = { }; var DataTableController = function () { - DataTableController.$inject = ["$scope", "$filter", "$log", "$transclude"]; - function DataTableController($scope, $filter, $log, $transclude) { + DataTableController.$inject = ["$scope", "$filter", "$log", "$transclude", "$window"]; + function DataTableController($scope, $filter, $log, $transclude, $window) { var _this6 = this; _classCallCheck(this, DataTableController); + $window.dt = this; Object.assign(this, { $scope: $scope, $filter: $filter, @@ -2070,6 +2082,14 @@ var DataTableController = function () { if (this.options.selectable && this.options.multiSelect) { this.selected = this.selected || []; + + this.$scope.$watch('dt.selected', function (newVal, oldVal) { + angular.forEach(_this7.options.columns, function (column) { + if (column.headerCheckbox && angular.isFunction(column.headerCheckboxCallback)) { + column.headerCheckboxCallback(_this7); + } + }); + }, true); } } }, { @@ -2203,24 +2223,27 @@ var DataTableController = function () { this.options.internal.setYOffset(offsetY); } }, { - key: "onHeaderCheckboxChange", - value: function onHeaderCheckboxChange() { - if (this.rows) { - var matches = this.selected.length === this.rows.length; - this.selected.splice(0, this.selected.length); + key: "selectAllRows", + value: function selectAllRows() { + var _selected; - if (!matches) { - var _selected; + this.selected.splice(0, this.selected.length); - (_selected = this.selected).push.apply(_selected, _toConsumableArray(this.rows)); - } - } + (_selected = this.selected).push.apply(_selected, _toConsumableArray(this.rows)); + + return this.isAllRowsSelected(); + } + }, { + key: "deselectAllRows", + value: function deselectAllRows() { + this.selected.splice(0, this.selected.length); + + return this.isAllRowsSelected(); } }, { key: "isAllRowsSelected", value: function isAllRowsSelected() { - if (this.rows) return false; - return this.selected.length === this.rows.length; + return !this.rows || !this.selected ? false : this.selected.length === this.rows.length; } }, { key: "onResized", @@ -2293,7 +2316,7 @@ function DataTableDirective($window, $timeout, $parse) { id = ObjectId(); DataTableService.saveColumns(id, columns); - return "
\n \n \n \n \n \n \n
"; + return "
\n \n \n \n \n \n \n
"; }, compile: function compile(tElem, tAttrs) { return { diff --git a/release/dataTable.es6.js b/release/dataTable.es6.js index a66117e..436ca4a 100644 --- a/release/dataTable.es6.js +++ b/release/dataTable.es6.js @@ -1590,6 +1590,17 @@ function NextSortDirection(sortType, currentSort) { } class HeaderCellController{ + constructor($scope){ + this.$scope = $scope; + + if (this.$scope.$parent.$parent.$parent.$parent.dt) { + this.dt = this.$scope.$parent.$parent.$parent.$parent.dt; + } + + if (this.column.headerCheckbox) { + this.column.headerCheckboxCallback = this.rowSelected; + } + } /** * Calculates the styles for the header cell directive * @return {styles} @@ -1659,13 +1670,18 @@ class HeaderCellController{ }); } + rowSelected(dt){ + this.allRowsSelected = (dt.selected) && (dt.rows.length === dt.selected.length); + } + /** - * Invoked when the header cell directive checkbox was changed + * Invoked when the header cell directive checkbox is changed */ - onCheckboxChange(){ - this.onCheckboxChanged(); + checkboxChangeCallback(){ + return this.isAllRowsSelected = this.column.allRowsSelected ? + this.dt.selectAllRows() : + this.dt.deselectAllRows(); } - } function HeaderCellDirective($compile){ @@ -1677,7 +1693,6 @@ function HeaderCellDirective($compile){ bindToController: { options: '=', column: '=', - onCheckboxChange: '&', onSort: '&', sortType: '=', onResize: '&', @@ -1697,8 +1712,8 @@ function HeaderCellDirective($compile){ max-width="hcell.column.maxWidth"> @@ -1737,7 +1752,6 @@ function HeaderCellDirective($compile){ } class HeaderController { - /** * Returns the styles for the header directive. * @param {object} scope @@ -1807,14 +1821,6 @@ class HeaderController { return styles; } - /** - * Invoked when the header cell directive's checkbox has changed. - * @param {scope} - */ - onCheckboxChanged(){ - this.onCheckboxChange(); - } - /** * Occurs when a header cell directive triggered a resize * @param {object} scope @@ -1827,7 +1833,6 @@ class HeaderController { width: width }); } - } function HeaderDirective($timeout){ @@ -1840,13 +1845,13 @@ function HeaderDirective($timeout){ options: '=', columns: '=', columnWidths: '=', + selectedRows: '=?', + allRows: '=', onSort: '&', - onResize: '&', - onCheckboxChange: '&' + onResize: '&' }, template: `
-
@@ -2598,7 +2602,7 @@ class DataTableController { * @param {filter} */ /*@ngInject*/ - constructor($scope, $filter, $log, $transclude){ + constructor($scope, $filter, $log, $transclude, $window){$window.dt = this; Object.assign(this, { $scope: $scope, $filter: $filter, @@ -2646,6 +2650,14 @@ class DataTableController { if(this.options.selectable && this.options.multiSelect){ this.selected = this.selected || []; + + this.$scope.$watch('dt.selected', (newVal, oldVal) => { + angular.forEach(this.options.columns, (column) => { + if (column.headerCheckbox && angular.isFunction(column.headerCheckboxCallback)) { + column.headerCheckboxCallback(this); + } + }); + }, true); } } @@ -2815,18 +2827,18 @@ class DataTableController { this.options.internal.setYOffset(offsetY); } - /** - * Invoked when the header checkbox directive has changed. - */ - onHeaderCheckboxChange(){ - if(this.rows){ - var matches = this.selected.length === this.rows.length; - this.selected.splice(0, this.selected.length); + selectAllRows(){ + this.selected.splice(0, this.selected.length); - if(!matches){ - this.selected.push(...this.rows); - } - } + this.selected.push(...this.rows); + + return this.isAllRowsSelected(); + } + + deselectAllRows(){ + this.selected.splice(0, this.selected.length); + + return this.isAllRowsSelected(); } /** @@ -2834,8 +2846,7 @@ class DataTableController { * @return {Boolean} if all selected */ isAllRowsSelected(){ - if(this.rows) return false; - return this.selected.length === this.rows.length; + return (!this.rows || !this.selected) ? false : this.selected.length === this.rows.length; } /** @@ -2891,7 +2902,6 @@ class DataTableController { row: row }); } - } function DataTableDirective($window, $timeout, $parse){ @@ -2923,12 +2933,12 @@ function DataTableDirective($window, $timeout, $parse){ return `
\n\n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n
", + template: "\n
\n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n
", replace: true, link: function link($scope, $elm, $attrs, ctrl) { @@ -2060,12 +2071,13 @@ }; var DataTableController = function () { - DataTableController.$inject = ["$scope", "$filter", "$log", "$transclude"]; - function DataTableController($scope, $filter, $log, $transclude) { + DataTableController.$inject = ["$scope", "$filter", "$log", "$transclude", "$window"]; + function DataTableController($scope, $filter, $log, $transclude, $window) { var _this6 = this; _classCallCheck(this, DataTableController); + $window.dt = this; Object.assign(this, { $scope: $scope, $filter: $filter, @@ -2111,6 +2123,14 @@ if (this.options.selectable && this.options.multiSelect) { this.selected = this.selected || []; + + this.$scope.$watch('dt.selected', function (newVal, oldVal) { + angular.forEach(_this7.options.columns, function (column) { + if (column.headerCheckbox && angular.isFunction(column.headerCheckboxCallback)) { + column.headerCheckboxCallback(_this7); + } + }); + }, true); } } }, { @@ -2244,24 +2264,27 @@ this.options.internal.setYOffset(offsetY); } }, { - key: "onHeaderCheckboxChange", - value: function onHeaderCheckboxChange() { - if (this.rows) { - var matches = this.selected.length === this.rows.length; - this.selected.splice(0, this.selected.length); + key: "selectAllRows", + value: function selectAllRows() { + var _selected; - if (!matches) { - var _selected; + this.selected.splice(0, this.selected.length); - (_selected = this.selected).push.apply(_selected, _toConsumableArray(this.rows)); - } - } + (_selected = this.selected).push.apply(_selected, _toConsumableArray(this.rows)); + + return this.isAllRowsSelected(); + } + }, { + key: "deselectAllRows", + value: function deselectAllRows() { + this.selected.splice(0, this.selected.length); + + return this.isAllRowsSelected(); } }, { key: "isAllRowsSelected", value: function isAllRowsSelected() { - if (this.rows) return false; - return this.selected.length === this.rows.length; + return !this.rows || !this.selected ? false : this.selected.length === this.rows.length; } }, { key: "onResized", @@ -2334,7 +2357,7 @@ id = ObjectId(); DataTableService.saveColumns(id, columns); - return "
\n \n \n \n \n \n \n
"; + return "
\n \n \n \n \n \n \n
"; }, compile: function compile(tElem, tAttrs) { return { diff --git a/release/dataTable.min.js b/release/dataTable.min.js index 7e35983..8854fb0 100644 --- a/release/dataTable.min.js +++ b/release/dataTable.min.js @@ -1,8 +1,8 @@ /** * angular-data-table - A feature-rich but lightweight ES6 AngularJS Data Table crafted for large data sets! - * @version v0.6.0 + * @version v0.6.1 * @link http://swimlane.com/ * @license */ -!function(e,t){if("function"==typeof define&&define.amd)define("DataTable",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.DataTable=n.exports}}(this,function(e){"use strict";function t(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\n
    \n
  • \n \n
  • \n
  • \n \n
  • \n
  • \n {{pg.text}}\n
  • \n
  • \n \n
  • \n
  • \n \n
  • \n
\n
',replace:!0}}function i(){return{restrict:"E",controller:B,controllerAs:"footer",scope:!0,bindToController:{paging:"=",onPage:"&"},template:'',replace:!0}}function r(e,t,n,o){return{restrict:"E",controller:G,scope:!0,controllerAs:"cell",bindToController:{options:"=",value:"=",selected:"=",column:"=",row:"=",expanded:"=",hasChildren:"=",onTreeToggle:"&",onCheckboxChange:"&"},template:'
\n \n \n \n
',replace:!0,compile:function(){return{pre:function(e,n,o,i){function r(){s=i.options.$outer.$new(!1),s.getValue=i.getValue}var s,l=angular.element(n[0].querySelector(".dt-cell-content"));(i.column.template||i.column.cellRenderer)&&r(),e.$watch("cell.row",function(){if(s&&(s.$destroy(),r(),s.$cell=i.value,s.$row=i.row,s.$column=i.column,s.$$watchers=null),i.column.template){l.empty();var e=angular.element(""+i.column.template.trim()+"");l.append(t(e)(s))}else if(i.column.cellRenderer){l.empty();var e=angular.element(i.column.cellRenderer(s,l));l.append(t(e)(s))}else l[0].innerHTML=i.getValue()},!0)}}}}}function s(e){return e=e.replace(/[^a-zA-Z0-9 ]/g," "),e=e.replace(/([a-z](?=[A-Z]))/g,"$1 "),e=e.replace(/([^a-zA-Z0-9 ])|^[0-9]+/g,"").trim().toLowerCase(),e=e.replace(/([ 0-9]+)([a-zA-Z])/g,function(e,t,n){return t.trim()+n.toUpperCase()})}function l(e){var t=s(e);return H[t]||(void 0!==D[M.css+e]?H[t]=M.css+e:void 0!==D[e]&&(H[t]=e)),H[t]}function a(e,t,n){V?!I&&j?(e[N]="translate3d("+t+"px, "+n+"px, 0)",e[O]="hidden"):e[s(N)]="translate("+t+"px, "+n+"px)":(e.top=n+"px",e.left=t+"px")}function c(){return{restrict:"E",controller:F,controllerAs:"group",bindToController:{row:"=",onGroupToggle:"&",expanded:"=",options:"="},scope:!0,replace:!0,template:'\n
\n \n \n \n \n
',link:function(e,t,n,o){a(t[0].style,0,o.row.$$index*o.options.rowHeight),o.options.internal.styleTranslator.register(e.$index,t)}}}function d(e,t){if(!e||!t)return e;var n=e,o=t.split(".");if(o.length)for(var i=0,r=o.length;i\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
',replace:!0}}function h(){return{controller:q,restrict:"A",require:"^dtBody",controllerAs:"selCtrl"}}function p(e,t){return{restrict:"E",require:"^dtBody",transclude:!0,replace:!0,template:'
',link:function(e,t,n,o){function i(){o.options.internal.offsetY=l,o.options.internal.offsetX=a,o.updatePage(),o.options.scrollbarV&&o.getRows(),o.options.$outer.$digest(),s=!1}function r(){s||(Y(i),s=!0)}var s=!1,l=0,a=0,c=t.parent();o.options.internal.styleTranslator=new Z(o.options.rowHeight),o.options.internal.setYOffset=function(e){c[0].scrollTop=e},c.on("scroll",function(e){l=this.scrollTop,a=this.scrollLeft,r()}),e.$on("$destroy",function(){c.off("scroll")}),e.scrollerStyles=function(){if(o.options.scrollbarV)return{height:o.count*o.options.rowHeight+"px"}}}}}function g(e){return{restrict:"E",controller:_,controllerAs:"body",bindToController:{columns:"=",columnWidths:"=",rows:"=",options:"=",selected:"=?",expanded:"=?",onPage:"&",onTreeToggle:"&",onSelect:"&",onRowClick:"&",onRowDblClick:"&"},scope:!0,template:'\n
\n
\n
\n
\n
\n
\n \n \n \n \n \n \n
\n
\n
\n
\n
'}}function f(e,t){return"single"===e?"asc"===t?"desc":"asc":t?"asc"===t?"desc":void 0:"asc"}function m(e){return{restrict:"E",controller:K,controllerAs:"hcell",scope:!0,bindToController:{options:"=",column:"=",onCheckboxChange:"&",onSort:"&",sortType:"=",onResize:"&",selected:"="},replace:!0,template:'
\n
\n \n \n \n \n
\n
',compile:function(){return{pre:function(t,n,o,i){var r=n[0].querySelector(".dt-header-cell-label"),s=void 0;if((i.column.headerTemplate||i.column.headerRenderer)&&(s=i.options.$outer.$new(!1),s.$header=i.column.name,s.$index=t.$index),i.column.headerTemplate){var l=angular.element(""+i.column.headerTemplate.trim()+"");angular.element(r).append(e(l)(s))}else if(i.column.headerRenderer){var a=angular.element(i.column.headerRenderer(n));angular.element(r).append(e(a)(s)[0])}else{var c=i.column.name;void 0!==c&&null!==c||(c=""),r.textContent=c}}}}}}function v(e){return{restrict:"E",controller:J,controllerAs:"header",scope:!0,bindToController:{options:"=",columns:"=",columnWidths:"=",onSort:"&",onResize:"&",onCheckboxChange:"&"},template:'\n
\n\n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n
',replace:!0,link:function(t,n,o,i){t.columnsResorted=function(t,n){var o=r(n),s=angular.element(t.currentTarget),l=-1;angular.forEach(s.children(),function(e,t){n===angular.element(e).attr("data-id")&&(l=t)}),e(function(){angular.forEach(i.columns,function(e){var t=e.indexOf(o);if(t>-1){var n=e[l],r=i.options.columns.indexOf(n),s=i.options.columns.indexOf(o);return i.options.columns.splice(s,1),i.options.columns.splice(r,0,o),!1}})})};var r=function(e){var t=i.columns.left.concat(i.columns.center).concat(i.columns.right);return t.find(function(t){return t.$id===e})}}}}function w(e){return{restrict:"A",scope:{isSortable:"=sortable",onSortableSort:"&"},link:function(e,t,n){function o(e,t){if(e.parentNode==t.parentNode)for(var n=e;n;n=n.previousSibling)if(n===t)return!0;return!1}function i(e){var t=e.target;o(l,t)?t.parentNode.insertBefore(l,t):t.nextSibling&&t.hasAttribute("draggable")&&t.parentNode.insertBefore(l,t.nextSibling.nextSibling)}function r(n){n.preventDefault(),l.classList.remove("dt-clone"),t.off("dragend",r),t.off("dragenter",i),a!==l.nextSibling&&e.onSortableSort({event:n,columnId:angular.element(l).attr("data-id")})}function s(n){return!!e.isSortable&&(n=n.originalEvent||n,l=n.target,a=l.nextSibling,l.classList.add("dt-clone"),n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("Text",l.textContent),t.on("dragenter",i),void t.on("dragend",r))}var l,a;t[0];t.on("dragstart",s),e.$on("$destroy",function(){t.off("dragstart",s)})}}}function y(e,t){return{restrict:"A",scope:{isResizable:"=resizable",minWidth:"=",maxWidth:"=",onResize:"&"},link:function(n,o,i){function r(e){e=e.originalEvent||e;var t=c[0].clientWidth,o=e.movementX||e.mozMovementX||e.screenX-l,i=t+(o||0);l=e.screenX,(!n.minWidth||i>=n.minWidth)&&(!n.maxWidth||i<=n.maxWidth)&&c.css({width:i+"px"})}function s(){n.onResize&&t(function(){var e=c[0].clientWidth;e
'),c=o.parent();a.on("mousedown",function(t){return!!o[0].classList.contains("resizable")&&(t.stopPropagation(),t.preventDefault(),e.on("mousemove",r),void e.on("mouseup",s))}),o.append(a)}}}function b(e,t,n){var o,i,r,s=null,l=0;n||(n={});var a=function(){l=n.leading===!1?0:new Date,s=null,r=e.apply(o,i)};return function(){var c=new Date;l||n.leading!==!1||(l=c);var d=t-(c-l);return o=this,i=arguments,d<=0?(clearTimeout(s),s=null,l=c,r=e.apply(o,i)):s||n.trailing===!1||(s=setTimeout(a,d)),r}}function C(){var e=document.createElement("div");e.style.visibility="hidden",e.style.width="100px",e.style.msOverflowStyle="scrollbar",document.body.appendChild(e);var t=e.offsetWidth;e.style.overflow="scroll";var n=document.createElement("div");n.style.width="100%",e.appendChild(n);var o=n.offsetWidth;return e.parentNode.removeChild(e),t-o}function x(){var e=((new Date).getTime()/1e3|0).toString(16);return e+"xxxxxxxxxxxxxxxx".replace(/[x]/g,function(){return(16*Math.random()|0).toString(16)}).toLowerCase()}function k(e,t,n){angular.forEach(e,function(e){e.forEach(function(e){e.canAutoResize?e.width=0:(t-=e.width,n-=e.flexGrow)})});var o={},i=t,r=function(){var t=i/n;i=0,angular.forEach(e,function(e){e.forEach(function(e,n){if(e.canAutoResize&&!o[n]){var r=e.width+e.flexGrow*t;void 0!==e.minWidth&&r-1?e.slice(n,e.length).filter(function(e){return e.canAutoResize}):e.filter(function(e){return e.canAutoResize});e.forEach(function(e){o+=e.canAutoResize?e.$$oldWidth||e.width:e.width});var r=t-o,s=r/i.length,l=o>t;i.forEach(function(e){if(l)e.width=e.$$oldWidth||e.width;else{e.$$oldWidth||(e.$$oldWidth=e.width);var t=e.$$oldWidth+s;e.minWith&&te.maxWidth?e.width=e.maxWidth:e.width=t}})}function z(e,t){return{left:T(e.left),center:T(e.center),right:T(e.right),total:T(t)}}function W(e,t,n){return{restrict:"E",replace:!0,controller:ne,scope:!0,bindToController:{options:"=",rows:"=",selected:"=?",expanded:"=?",onSelect:"&",onSort:"&",onTreeToggle:"&",onPage:"&",onRowClick:"&",onRowDblClick:"&",onColumnResize:"&"},controllerAs:"dt",template:function(e){var t=e[0].getElementsByTagName("column"),n=x();return Q.saveColumns(n,t),'
\n \n \n \n \n \n \n
'},compile:function(o,i){return{pre:function(o,i,r,s){function l(){var e=i[0].getBoundingClientRect();if(s.options.internal.innerWidth=Math.floor(e.width),s.options.scrollbarV){var t=e.height;s.options.headerHeight&&(t-=s.options.headerHeight),s.options.footerHeight&&(t-=s.options.footerHeight),s.options.internal.bodyHeight=t,s.calculatePageSize()}s.adjustColumns()}Q.buildColumns(o,n);var a=i.attr("data-column-id"),c=Q.columns[a];c&&(s.options.columns=c),s.transposeColumnDefaults(),s.options.internal.scrollBarWidth=C(),e.addEventListener("resize",b(function(){t(l)}));var d=function u(){var e=i[0].getBoundingClientRect(),n=e.width&&e.height;n?l():t(u,100)};d(),i.addClass("dt-loaded"),o.$on("$destroy",function(){angular.element(e).off("resize")})}}}}}W.$inject=["$window","$timeout","$parse"],y.$inject=["$document","$timeout"],w.$inject=["$timeout"],v.$inject=["$timeout"],m.$inject=["$compile"],g.$inject=["$timeout"],p.$inject=["$timeout","$rootScope"],r.$inject=["$rootScope","$compile","$log","$timeout"],Object.defineProperty(e,"__esModule",{value:!0});var E=function(){function e(e,t){for(var n=0;n0&&e<=this.totalPages&&(this.page=e,this.onPage({page:e}))}},{key:"prevPage",value:function(){this.page>1&&this.selectPage(--this.page)}},{key:"nextPage",value:function(){this.selectPage(++this.page)}},{key:"canPrevious",value:function(){return this.page>1}},{key:"canNext",value:function(){return this.page-1?this.selected.splice(i,1):(this.options.multiSelectOnShift&&1===this.selected.length&&this.selected.splice(0,1),this.selected.push(n),this.body.onSelect({rows:[n]}))}this.prevIndex=t}else this.selected=n,this.body.onSelect({rows:[n]})}},{key:"selectRowsBetween",value:function(e){for(var t=e=this.prevIndex&&o<=e,l=o<=this.prevIndex&&o>=e,a={};if(a=t?{start:e,end:this.prevIndex-e}:{start:this.prevIndex,end:e+1},t&&l||!t&&s){var c=this.selected.indexOf(r);if(t&&c>-1){this.selected.splice(c,1);continue}o>=a.start&&ot)&&(i.getRows(),r=!0)}),t.$watch("body.options.paging.count",function(e){i.count=e,i.updatePage()}),t.$watch("body.options.paging.offset",function(e){i.options.paging.size&&i.onPage({offset:e,size:i.options.paging.size})})}}return e.$inject=["$scope","$timeout"],E(e,[{key:"rowsUpdated",value:function(e,n){if(e)if(this.options.paging.externalPaging||(this.options.paging.count=e.length),this.count=this.options.paging.count,(this.treeColumn||this.groupColumn)&&this.buildRowsByGroup(),this.options.scrollbarV){var o=e&&n&&(e.length===n.length||e.lengthn?Math.ceil(o):e,isNaN(o)||(this.options.paging.offset=o)}},{key:"buildRowsByGroup",value:function(){this.index={},this.rowsByGroup={};for(var e=this.treeColumn?this.treeColumn.relationProp:this.groupColumn.prop,t=0,n=this.rows.length;t-1:this.selected===e),t}},{key:"buildTree",value:function(){function e(t,o,i){t.forEach(function(t){ -var r=t[n.treeColumn.relationProp],s=t[n.treeColumn.prop],l=n.rowsByGroup[s],a=n.expanded[s];(i>0||!r)&&(o.push(t),l&&l.length>0&&a&&e(l,o,i+1))})}var t=[],n=this;return e(this.rows,t,0),t}},{key:"getRows",value:function(e){if((this.treeColumn||this.groupColumn)&&!this.rowsByGroup)return!1;var t;this.treeColumn?(t=this.treeTemp||[],!e&&this.treeTemp||(this.treeTemp=t=this.buildTree(),this.count=t.length,this.tempRows.splice(0,this.tempRows.length))):this.groupColumn?(t=this.groupsTemp||[],!e&&this.groupsTemp||(this.groupsTemp=t=this.buildGroups(),this.count=t.length)):(t=this.rows,e===!0&&this.tempRows.splice(0,this.tempRows.length));var n=0,o=this.getFirstLastIndexes(),i=o.first;for(this.tempRows.splice(0,o.last-o.first);it.sortPriority)return 1;if(e.sortPriority-1){var e=this.options.columns[n];e.width=t,e.canAutoResize=!1,this.adjustColumns(n),this.calculateColumns()}this.onColumnResize&&this.onColumnResize({column:e,width:t})}},{key:"onSelected",value:function(e){this.onSelect({rows:e})}},{key:"onRowClicked",value:function(e){this.onRowClick({row:e})}},{key:"onRowDblClicked",value:function(e){this.onRowDblClick({row:e})}}]),e}(),oe=angular.module("data-table",[]).directive("dtable",W).directive("resizable",y).directive("sortable",w).directive("dtHeader",v).directive("dtHeaderCell",m).directive("dtBody",g).directive("dtScroller",p).directive("dtSeletion",h).directive("dtRow",u).directive("dtGroupRow",c).directive("dtCell",r).directive("dtFooter",i).directive("dtPager",o);e["default"]=oe}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define("DataTable",["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.DataTable=n.exports}}(this,function(e){"use strict";function t(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t\n
    \n
  • \n \n
  • \n
  • \n \n
  • \n
  • \n {{pg.text}}\n
  • \n
  • \n \n
  • \n
  • \n \n
  • \n
\n
',replace:!0}}function i(){return{restrict:"E",controller:B,controllerAs:"footer",scope:!0,bindToController:{paging:"=",onPage:"&"},template:'',replace:!0}}function s(e,t,n,o){return{restrict:"E",controller:G,scope:!0,controllerAs:"cell",bindToController:{options:"=",value:"=",selected:"=",column:"=",row:"=",expanded:"=",hasChildren:"=",onTreeToggle:"&",onCheckboxChange:"&"},template:'
\n \n \n \n
',replace:!0,compile:function(){return{pre:function(e,n,o,i){function s(){r=i.options.$outer.$new(!1),r.getValue=i.getValue}var r,l=angular.element(n[0].querySelector(".dt-cell-content"));(i.column.template||i.column.cellRenderer)&&s(),e.$watch("cell.row",function(){if(r&&(r.$destroy(),s(),r.$cell=i.value,r.$row=i.row,r.$column=i.column,r.$$watchers=null),i.column.template){l.empty();var e=angular.element(""+i.column.template.trim()+"");l.append(t(e)(r))}else if(i.column.cellRenderer){l.empty();var e=angular.element(i.column.cellRenderer(r,l));l.append(t(e)(r))}else l[0].innerHTML=i.getValue()},!0)}}}}}function r(e){return e=e.replace(/[^a-zA-Z0-9 ]/g," "),e=e.replace(/([a-z](?=[A-Z]))/g,"$1 "),e=e.replace(/([^a-zA-Z0-9 ])|^[0-9]+/g,"").trim().toLowerCase(),e=e.replace(/([ 0-9]+)([a-zA-Z])/g,function(e,t,n){return t.trim()+n.toUpperCase()})}function l(e){var t=r(e);return D[t]||(void 0!==H[M.css+e]?D[t]=M.css+e:void 0!==H[e]&&(D[t]=e)),D[t]}function a(e,t,n){V?!I&&j?(e[N]="translate3d("+t+"px, "+n+"px, 0)",e[O]="hidden"):e[r(N)]="translate("+t+"px, "+n+"px)":(e.top=n+"px",e.left=t+"px")}function c(){return{restrict:"E",controller:F,controllerAs:"group",bindToController:{row:"=",onGroupToggle:"&",expanded:"=",options:"="},scope:!0,replace:!0,template:'\n
\n \n \n \n \n
',link:function(e,t,n,o){a(t[0].style,0,o.row.$$index*o.options.rowHeight),o.options.internal.styleTranslator.register(e.$index,t)}}}function d(e,t){if(!e||!t)return e;var n=e,o=t.split(".");if(o.length)for(var i=0,s=o.length;i\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
',replace:!0}}function h(){return{controller:q,restrict:"A",require:"^dtBody",controllerAs:"selCtrl"}}function p(e,t){return{restrict:"E",require:"^dtBody",transclude:!0,replace:!0,template:'
',link:function(e,t,n,o){function i(){o.options.internal.offsetY=l,o.options.internal.offsetX=a,o.updatePage(),o.options.scrollbarV&&o.getRows(),o.options.$outer.$digest(),r=!1}function s(){r||(Y(i),r=!0)}var r=!1,l=0,a=0,c=t.parent();o.options.internal.styleTranslator=new Z(o.options.rowHeight),o.options.internal.setYOffset=function(e){c[0].scrollTop=e},c.on("scroll",function(e){l=this.scrollTop,a=this.scrollLeft,s()}),e.$on("$destroy",function(){c.off("scroll")}),e.scrollerStyles=function(){if(o.options.scrollbarV)return{height:o.count*o.options.rowHeight+"px"}}}}}function g(e){return{restrict:"E",controller:_,controllerAs:"body",bindToController:{columns:"=",columnWidths:"=",rows:"=",options:"=",selected:"=?",expanded:"=?",onPage:"&",onTreeToggle:"&",onSelect:"&",onRowClick:"&",onRowDblClick:"&"},scope:!0,template:'\n
\n
\n
\n
\n
\n
\n \n \n \n \n \n \n
\n
\n
\n
\n
'}}function f(e,t){return"single"===e?"asc"===t?"desc":"asc":t?"asc"===t?"desc":void 0:"asc"}function m(e){return{restrict:"E",controller:K,controllerAs:"hcell",scope:!0,bindToController:{options:"=",column:"=",onSort:"&",sortType:"=",onResize:"&",selected:"="},replace:!0,template:'
\n
\n \n \n \n \n
\n
',compile:function(){return{pre:function(t,n,o,i){var s=n[0].querySelector(".dt-header-cell-label"),r=void 0;if((i.column.headerTemplate||i.column.headerRenderer)&&(r=i.options.$outer.$new(!1),r.$header=i.column.name,r.$index=t.$index),i.column.headerTemplate){var l=angular.element(""+i.column.headerTemplate.trim()+"");angular.element(s).append(e(l)(r))}else if(i.column.headerRenderer){var a=angular.element(i.column.headerRenderer(n));angular.element(s).append(e(a)(r)[0])}else{var c=i.column.name;void 0!==c&&null!==c||(c=""),s.textContent=c}}}}}}function v(e){return{restrict:"E",controller:J,controllerAs:"header",scope:!0,bindToController:{options:"=",columns:"=",columnWidths:"=",selectedRows:"=?",allRows:"=",onSort:"&",onResize:"&"},template:'\n
\n
\n
\n \n \n
\n
\n \n \n
\n
\n \n \n
\n
\n
',replace:!0,link:function(t,n,o,i){t.columnsResorted=function(t,n){var o=s(n),r=angular.element(t.currentTarget),l=-1;angular.forEach(r.children(),function(e,t){n===angular.element(e).attr("data-id")&&(l=t)}),e(function(){angular.forEach(i.columns,function(e){var t=e.indexOf(o);if(t>-1){var n=e[l],s=i.options.columns.indexOf(n),r=i.options.columns.indexOf(o);return i.options.columns.splice(r,1),i.options.columns.splice(s,0,o),!1}})})};var s=function(e){var t=i.columns.left.concat(i.columns.center).concat(i.columns.right);return t.find(function(t){return t.$id===e})}}}}function w(e){return{restrict:"A",scope:{isSortable:"=sortable",onSortableSort:"&"},link:function(e,t,n){function o(e,t){if(e.parentNode==t.parentNode)for(var n=e;n;n=n.previousSibling)if(n===t)return!0;return!1}function i(e){var t=e.target;o(l,t)?t.parentNode.insertBefore(l,t):t.nextSibling&&t.hasAttribute("draggable")&&t.parentNode.insertBefore(l,t.nextSibling.nextSibling)}function s(n){n.preventDefault(),l.classList.remove("dt-clone"),t.off("dragend",s),t.off("dragenter",i),a!==l.nextSibling&&e.onSortableSort({event:n,columnId:angular.element(l).attr("data-id")})}function r(n){return!!e.isSortable&&(n=n.originalEvent||n,l=n.target,a=l.nextSibling,l.classList.add("dt-clone"),n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("Text",l.textContent),t.on("dragenter",i),void t.on("dragend",s))}var l,a;t[0];t.on("dragstart",r),e.$on("$destroy",function(){t.off("dragstart",r)})}}}function y(e,t){return{restrict:"A",scope:{isResizable:"=resizable",minWidth:"=",maxWidth:"=",onResize:"&"},link:function(n,o,i){function s(e){e=e.originalEvent||e;var t=c[0].clientWidth,o=e.movementX||e.mozMovementX||e.screenX-l,i=t+(o||0);l=e.screenX,(!n.minWidth||i>=n.minWidth)&&(!n.maxWidth||i<=n.maxWidth)&&c.css({width:i+"px"})}function r(){n.onResize&&t(function(){var e=c[0].clientWidth;e
'),c=o.parent();a.on("mousedown",function(t){return!!o[0].classList.contains("resizable")&&(t.stopPropagation(),t.preventDefault(),e.on("mousemove",s),void e.on("mouseup",r))}),o.append(a)}}}function b(e,t,n){var o,i,s,r=null,l=0;n||(n={});var a=function(){l=n.leading===!1?0:new Date,r=null,s=e.apply(o,i)};return function(){var c=new Date;l||n.leading!==!1||(l=c);var d=t-(c-l);return o=this,i=arguments,d<=0?(clearTimeout(r),r=null,l=c,s=e.apply(o,i)):r||n.trailing===!1||(r=setTimeout(a,d)),s}}function C(){var e=document.createElement("div");e.style.visibility="hidden",e.style.width="100px",e.style.msOverflowStyle="scrollbar",document.body.appendChild(e);var t=e.offsetWidth;e.style.overflow="scroll";var n=document.createElement("div");n.style.width="100%",e.appendChild(n);var o=n.offsetWidth;return e.parentNode.removeChild(e),t-o}function x(){var e=((new Date).getTime()/1e3|0).toString(16);return e+"xxxxxxxxxxxxxxxx".replace(/[x]/g,function(){return(16*Math.random()|0).toString(16)}).toLowerCase()}function k(e,t,n){angular.forEach(e,function(e){e.forEach(function(e){e.canAutoResize?e.width=0:(t-=e.width,n-=e.flexGrow)})});var o={},i=t,s=function(){var t=i/n;i=0,angular.forEach(e,function(e){e.forEach(function(e,n){if(e.canAutoResize&&!o[n]){var s=e.width+e.flexGrow*t;void 0!==e.minWidth&&s-1?e.slice(n,e.length).filter(function(e){return e.canAutoResize}):e.filter(function(e){return e.canAutoResize});e.forEach(function(e){o+=e.canAutoResize?e.$$oldWidth||e.width:e.width});var s=t-o,r=s/i.length,l=o>t;i.forEach(function(e){if(l)e.width=e.$$oldWidth||e.width;else{e.$$oldWidth||(e.$$oldWidth=e.width);var t=e.$$oldWidth+r;e.minWith&&te.maxWidth?e.width=e.maxWidth:e.width=t}})}function z(e,t){return{left:T(e.left),center:T(e.center),right:T(e.right),total:T(t)}}function E(e,t,n){return{restrict:"E",replace:!0,controller:ne,scope:!0,bindToController:{options:"=",rows:"=",selected:"=?",expanded:"=?",onSelect:"&",onSort:"&",onTreeToggle:"&",onPage:"&",onRowClick:"&",onRowDblClick:"&",onColumnResize:"&"},controllerAs:"dt",template:function(e){var t=e[0].getElementsByTagName("column"),n=x();return Q.saveColumns(n,t),'
\n \n \n \n \n \n \n
'},compile:function(o,i){return{pre:function(o,i,s,r){function l(){var e=i[0].getBoundingClientRect();if(r.options.internal.innerWidth=Math.floor(e.width),r.options.scrollbarV){var t=e.height;r.options.headerHeight&&(t-=r.options.headerHeight),r.options.footerHeight&&(t-=r.options.footerHeight),r.options.internal.bodyHeight=t,r.calculatePageSize()}r.adjustColumns()}Q.buildColumns(o,n);var a=i.attr("data-column-id"),c=Q.columns[a];c&&(r.options.columns=c),r.transposeColumnDefaults(),r.options.internal.scrollBarWidth=C(),e.addEventListener("resize",b(function(){t(l)}));var d=function u(){var e=i[0].getBoundingClientRect(),n=e.width&&e.height;n?l():t(u,100)};d(),i.addClass("dt-loaded"),o.$on("$destroy",function(){angular.element(e).off("resize")})}}}}}E.$inject=["$window","$timeout","$parse"],y.$inject=["$document","$timeout"],w.$inject=["$timeout"],v.$inject=["$timeout"],m.$inject=["$compile"],g.$inject=["$timeout"],p.$inject=["$timeout","$rootScope"],s.$inject=["$rootScope","$compile","$log","$timeout"],Object.defineProperty(e,"__esModule",{value:!0});var W=function(){function e(e,t){for(var n=0;n0&&e<=this.totalPages&&(this.page=e,this.onPage({page:e}))}},{key:"prevPage",value:function(){this.page>1&&this.selectPage(--this.page)}},{key:"nextPage",value:function(){this.selectPage(++this.page)}},{key:"canPrevious",value:function(){return this.page>1}},{key:"canNext",value:function(){return this.page-1?this.selected.splice(i,1):(this.options.multiSelectOnShift&&1===this.selected.length&&this.selected.splice(0,1),this.selected.push(n),this.body.onSelect({rows:[n]}))}this.prevIndex=t}else this.selected=n,this.body.onSelect({rows:[n]})}},{key:"selectRowsBetween",value:function(e){for(var t=e=this.prevIndex&&o<=e,l=o<=this.prevIndex&&o>=e,a={};if(a=t?{start:e,end:this.prevIndex-e}:{start:this.prevIndex,end:e+1},t&&l||!t&&r){var c=this.selected.indexOf(s);if(t&&c>-1){this.selected.splice(c,1);continue}o>=a.start&&ot)&&(i.getRows(),s=!0)}),t.$watch("body.options.paging.count",function(e){i.count=e,i.updatePage()}),t.$watch("body.options.paging.offset",function(e){i.options.paging.size&&i.onPage({offset:e,size:i.options.paging.size})})}}return e.$inject=["$scope","$timeout"],W(e,[{key:"rowsUpdated",value:function(e,n){if(e)if(this.options.paging.externalPaging||(this.options.paging.count=e.length),this.count=this.options.paging.count,(this.treeColumn||this.groupColumn)&&this.buildRowsByGroup(),this.options.scrollbarV){var o=e&&n&&(e.length===n.length||e.lengthn?Math.ceil(o):e,isNaN(o)||(this.options.paging.offset=o)}},{key:"buildRowsByGroup",value:function(){this.index={},this.rowsByGroup={};for(var e=this.treeColumn?this.treeColumn.relationProp:this.groupColumn.prop,t=0,n=this.rows.length;t-1:this.selected===e),t}},{key:"buildTree",value:function(){function e(t,o,i){t.forEach(function(t){var s=t[n.treeColumn.relationProp],r=t[n.treeColumn.prop],l=n.rowsByGroup[r],a=n.expanded[r];(i>0||!s)&&(o.push(t), +l&&l.length>0&&a&&e(l,o,i+1))})}var t=[],n=this;return e(this.rows,t,0),t}},{key:"getRows",value:function(e){if((this.treeColumn||this.groupColumn)&&!this.rowsByGroup)return!1;var t;this.treeColumn?(t=this.treeTemp||[],!e&&this.treeTemp||(this.treeTemp=t=this.buildTree(),this.count=t.length,this.tempRows.splice(0,this.tempRows.length))):this.groupColumn?(t=this.groupsTemp||[],!e&&this.groupsTemp||(this.groupsTemp=t=this.buildGroups(),this.count=t.length)):(t=this.rows,e===!0&&this.tempRows.splice(0,this.tempRows.length));var n=0,o=this.getFirstLastIndexes(),i=o.first;for(this.tempRows.splice(0,o.last-o.first);it.sortPriority)return 1;if(e.sortPriority-1){var e=this.options.columns[n];e.width=t,e.canAutoResize=!1,this.adjustColumns(n),this.calculateColumns()}this.onColumnResize&&this.onColumnResize({column:e,width:t})}},{key:"onSelected",value:function(e){this.onSelect({rows:e})}},{key:"onRowClicked",value:function(e){this.onRowClick({row:e})}},{key:"onRowDblClicked",value:function(e){this.onRowDblClick({row:e})}}]),e}(),oe=angular.module("data-table",[]).directive("dtable",E).directive("resizable",y).directive("sortable",w).directive("dtHeader",v).directive("dtHeaderCell",m).directive("dtBody",g).directive("dtScroller",p).directive("dtSeletion",h).directive("dtRow",u).directive("dtGroupRow",c).directive("dtCell",s).directive("dtFooter",i).directive("dtPager",o);e["default"]=oe}); \ No newline at end of file diff --git a/src/components/DataTableController.js b/src/components/DataTableController.js index 6a1a8d6..64296c5 100644 --- a/src/components/DataTableController.js +++ b/src/components/DataTableController.js @@ -1,5 +1,4 @@ import angular from 'angular'; -import _ from 'lodash'; import { TableDefaults, ColumnDefaults } from '../defaults'; import { AdjustColumnWidths, ForceFillColumnWidths } from '../utils/math'; import { ColumnsByPin, ColumnGroupWidths, CamelCase, ObjectId, ScrollbarWidth } from '../utils/utils'; @@ -62,8 +61,8 @@ export class DataTableController { this.selected = this.selected || []; this.$scope.$watch('dt.selected', (newVal, oldVal) => { - _.forEach(this.options.columns, (column) => { - if (column.headerCheckbox && _.isFunction(column.headerCheckboxCallback)) { + angular.forEach(this.options.columns, (column) => { + if (column.headerCheckbox && angular.isFunction(column.headerCheckboxCallback)) { column.headerCheckboxCallback(this); } }); From 2e95fa5f65256ba08949e2524027f78cfd5a6636 Mon Sep 17 00:00:00 2001 From: Jon Shaffer Date: Sun, 23 Oct 2016 14:35:15 -0400 Subject: [PATCH 7/7] updating bower.json version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 679a219..a039bb0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-data-table", - "version": "0.7.0", + "version": "0.7.1", "homepage": "https://github.com/Swimlane/angular-data-table", "author": { "name": "Swimlane",