Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(action): hide action column when there are no visible actions
Browse files Browse the repository at this point in the history
  • Loading branch information
VMBindraban authored and doktordirk committed Nov 11, 2016
1 parent 3e4af2b commit d1dfb96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/datatable.html
Expand Up @@ -44,7 +44,7 @@
</th>

<!-- Actions -->
<th if.bind="showActions()" t="Actions">Actions</th>
<th if.bind="showActions() && hasVisibleActions" t="Actions">Actions</th>
</tr>
</thead>
<tbody>
Expand All @@ -61,7 +61,7 @@
</td>

<!-- Actions -->
<td style="white-space: nowrap; width: 1px;" if.bind="showActions()">
<td style="white-space: nowrap; width: 1px;" show.bind="showActions() && hasVisibleActions">
<button if.bind="edit !== null" class="btn btn-sm btn-white" click.delegate="doEdit(row)">
<i class="fa fa-pencil"></i>
</button>
Expand Down
17 changes: 13 additions & 4 deletions src/datatable.js
Expand Up @@ -35,7 +35,8 @@ export class DataTable {
@bindable pages;
@bindable footer;

loading = false;
loading = false;
hasVisibleActions = false;

constructor(router, element, entityManager) {
this.router = router;
Expand Down Expand Up @@ -137,18 +138,26 @@ export class DataTable {

checkDisabled(action, row) {
if (typeof action.disabled === 'function') {
this.hasVisibleActions = true;

return action.disabled(row);
}

return false;
}

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() {
Expand Down

0 comments on commit d1dfb96

Please sign in to comment.