From d1dfb9660f678ab329f82b9c957b29dc9f1488e2 Mon Sep 17 00:00:00 2001 From: VMBindraban Date: Thu, 10 Nov 2016 15:08:09 +0100 Subject: [PATCH] feat(action): hide action column when there are no visible actions --- src/bootstrap/datatable.html | 4 ++-- src/datatable.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/datatable.html b/src/bootstrap/datatable.html index 91ae844..3b6070d 100755 --- a/src/bootstrap/datatable.html +++ b/src/bootstrap/datatable.html @@ -44,7 +44,7 @@ - Actions + Actions @@ -61,7 +61,7 @@ - + diff --git a/src/datatable.js b/src/datatable.js index 1c7de53..207b48f 100755 --- a/src/datatable.js +++ b/src/datatable.js @@ -35,7 +35,8 @@ export class DataTable { @bindable pages; @bindable footer; - loading = false; + loading = false; + hasVisibleActions = false; constructor(router, element, entityManager) { this.router = router; @@ -137,6 +138,8 @@ export class DataTable { checkDisabled(action, row) { if (typeof action.disabled === 'function') { + this.hasVisibleActions = true; + return action.disabled(row); } @@ -144,11 +147,17 @@ export class DataTable { } checkVisibility(action, row) { - if (typeof action.visible === 'function') { - return action.visible(row); + if (typeof action.visible !== 'function') { + return true; + } + + let isVisible = action.visible(row); + + if (isVisible) { + this.hasVisibleActions = true; } - return true; + return isVisible; } showActions() {