Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
MIT License

Copyright (c) 2023 Bhavesh Patel
Original work Copyright (c) 2023 Bhavesh Patel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Modified work Copyright (c) 2024 Gaurav Shinde

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ export class AppComponent {
| **totalRows** | number | 0 | total number of rows. **_totalRows_** required when **_isServerMode_** is true |
| **skin** | string | "bh-table-striped bh-table-hover" | custom class for skin ('**bh-table-striped**' - for stripe row, '**bh-table-hover**' - for hover row, '**bh-table-bordered**' - for bordered row, '**bh-table-compact**' - for compact table) |
| **loading** | boolean | false | enable loader |
| **hasCheckbox** | boolean | false | enable checkbox |
| **hasCheckbox** | boolean | false | enable checkbox

| **hasNestedTemplate** | boolean | false | enable
nested template

| **hasNestedTemplate** | templateRef | TemplateRef<any> | pass nested template whenever necessary

| **search** | string | "" | enable global search |
| **page** | number | 1 | current page |
| **pageSize** | number | 10 | number of rows per page |
Expand Down
9 changes: 9 additions & 0 deletions lib/column-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import { colDef } from './modals';
template: `
<ng-template #template>
<tr>
<th
*ngIf="all.hasNestedTemplate"
[class]="'bh-w-px'"
[ngClass]="{
'bh-sticky bh-bg-blue-light bh-z-[1]': all.stickyHeader || all.stickyFirstColumn,
'bh-top-0': all.stickyHeader,
'bh-left-0': all.stickyFirstColumn
}"
></th>
<th
*ngIf="all.hasCheckbox"
[class]="'bh-w-px'"
Expand Down
28 changes: 28 additions & 0 deletions lib/icon-caret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, Input, ViewChild, ViewContainerRef } from '@angular/core';
@Component({
selector: 'icon-caret',
template: `
<ng-template #template>
<svg [ngClass]="class" viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="0.3" fill="none" [attr.transform]="getTransform()">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M16.5303 8.96967C16.8232 9.26256 16.8232 9.73744 16.5303 10.0303L12.5303 14.0303C12.2374 14.3232 11.7626 14.3232 11.4697 14.0303L7.46967 10.0303C7.17678 9.73744 7.17678 9.26256 7.46967 8.96967C7.76256 8.67678 8.23744 8.67678 8.53033 8.96967L12 12.4393L15.4697 8.96967C15.7626 8.67678 16.2374 8.67678 16.5303 8.96967Z"
fill="currentColor"
></path>
</svg>
</ng-template>
`,
})
export class IconCaretComponent {
@ViewChild('template', { static: true }) template: any;
@Input() class: any;
@Input() rotationAngle: number = 0;
constructor(private viewContainerRef: ViewContainerRef) {}
ngOnInit() {
this.viewContainerRef.createEmbeddedView(this.template);
}
getTransform() {
return `matrix(1, 0, 0, 1, 0, 0) rotate(${this.rotationAngle})`;
}
}
64 changes: 39 additions & 25 deletions lib/ng-datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,52 @@

<tbody>
<ng-container *ngIf="filterRowCount">
<tr
*ngFor="let item of filterItems; let i = index; trackBy:trackFilterItems.bind(this)"
[ngClass]="[(isFunction(rowClass) ? rowClass(item) : rowClass), selectRowOnClick? 'bh-cursor-pointer':'']"
(click)="onRowClick(item, i)"
(dblclick)="onRowDoubleClick(item)"
>
<td *ngIf="hasCheckbox" [ngClass]="{'bh-sticky bh-left-0 bh-bg-blue-light': stickyFirstColumn}">
<div class="bh-checkbox" (click)="$event.stopPropagation();">
<input type="checkbox" value="{{item[uniqueKey] ? item[uniqueKey] : i}}" [(ngModel)]="item.selected" (change)="checkboxChange();" />
<div>
<icon-check class="check"></icon-check>
<ng-container *ngFor="let item of filterItems; let i = index; trackBy:trackFilterItems.bind(this)">
<tr
[ngClass]="[(isFunction(rowClass) ? rowClass(item) : rowClass), selectRowOnClick? 'bh-cursor-pointer':'']"
(click)="onRowClick(item, i)"
(dblclick)="onRowDoubleClick(item)"
>
<td *ngIf="hasNestedTemplate" [ngClass]="{'bh-sticky bh-left-0 bh-bg-blue-light': stickyFirstColumn}">
<div (click)="toggleNestedTable(i, $event)" class="caret-container" [ngClass]="{'active': item.showNested}">
<icon-caret [rotationAngle]="item.showNested ? 360 : 270" class="caret"></icon-caret>
</div>
</div>
</td>
<ng-container *ngFor="let col of columns; let j = index">
<td
*ngIf="!col.hide"
[ngClass]="[
</td>
<td *ngIf="hasCheckbox" [ngClass]="{'bh-sticky bh-left-0 bh-bg-blue-light': stickyFirstColumn}">
<div class="bh-checkbox" (click)="$event.stopPropagation();">
<input type="checkbox" value="{{item[uniqueKey] ? item[uniqueKey] : i}}" [(ngModel)]="item.selected" (change)="checkboxChange();" />
<div>
<icon-check class="check"></icon-check>
</div>
</div>
</td>
<ng-container *ngFor="let col of columns; let j = index">
<td
*ngIf="!col.hide"
[ngClass]="[
(isFunction(cellClass) ? cellClass(item) : cellClass),
j === 0 && stickyFirstColumn ? 'bh-sticky bh-left-0 bh-bg-blue-light' : '',
hasCheckbox && j === 0 && stickyFirstColumn ? 'bh-left-[52px]' : '',
col.cellClass ? col.cellClass : ''
]"
>
<ng-container *ngIf="hasSlot(col.field)">
<ng-container [ngTemplateOutlet]="getSlot(col.field)" [ngTemplateOutletContext]="{ data: item }"></ng-container>
</ng-container>
<div *ngIf="!hasSlot(col.field) && col.cellRenderer" [innerHTML]="sanitizeHtml(col.cellRenderer(item))"></div>
<ng-container *ngIf="!hasSlot(col.field) && !col.cellRenderer"> {{ cellValue(item, col.field) }} </ng-container>
</td>
>
<ng-container *ngIf="hasSlot(col.field)">
<ng-container [ngTemplateOutlet]="getSlot(col.field)" [ngTemplateOutletContext]="{ data: item }"></ng-container>
</ng-container>
<div *ngIf="!hasSlot(col.field) && col.cellRenderer" [innerHTML]="sanitizeHtml(col.cellRenderer(item))"></div>
<ng-container *ngIf="!hasSlot(col.field) && !col.cellRenderer"> {{ cellValue(item, col.field) }} </ng-container>
</td>
</ng-container>
</tr>

<ng-container *ngIf="item.showNested">
<tr class="nested-template">
<td [attr.colspan]="columns.length + 1">
<ng-container *ngTemplateOutlet="nestedTemplate; context: { data: item }"></ng-container>
</td>
</tr>
</ng-container>
</tr>
</ng-container>
</ng-container>
<tr *ngIf="!filterRowCount && !currentLoader">
<td [attr.colspan]="columns.length + 1">{{ noDataContent }}</td>
Expand Down
4 changes: 3 additions & 1 deletion lib/ng-datatable.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IconCheckComponent } from './icon-check';
import { IconDashComponent } from './icon-dash';
import { IconFilterComponent } from './icon-filter';
import { IconLoaderComponent } from './icon-loader';
import { IconCaretComponent } from './icon-caret';

// directive
import { SlotDirective } from './slot.directive';
Expand All @@ -23,8 +24,9 @@ import { SlotDirective } from './slot.directive';
IconDashComponent,
IconFilterComponent,
IconLoaderComponent,
IconCaretComponent,
SlotDirective,
],
exports: [NgDataTableComponent, ColumnFilterComponent, ColumnHeaderComponent, IconCheckComponent, IconDashComponent, IconFilterComponent, IconLoaderComponent, SlotDirective],
exports: [NgDataTableComponent, ColumnFilterComponent, ColumnHeaderComponent, IconCheckComponent, IconDashComponent, IconFilterComponent, IconLoaderComponent, IconCaretComponent, SlotDirective],
})
export class DataTableModule {}
8 changes: 8 additions & 0 deletions lib/ng-datatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class NgDataTableComponent {
@Input() stickyFirstColumn: boolean = false;
@Input() cloneHeaderInFooter: boolean = false;
@Input() selectRowOnClick: boolean = false;
@Input() nestedTemplate: TemplateRef<any>;
@Input() hasNestedTemplate: boolean = false;

// events
@Output() changeServer = new EventEmitter<any>();
Expand Down Expand Up @@ -209,6 +211,7 @@ export class NgDataTableComponent {
stickyFirstColumn: this.stickyFirstColumn,
cloneHeaderInFooter: this.cloneHeaderInFooter,
selectRowOnClick: this.selectRowOnClick,
hasNestedTemplate: this.hasNestedTemplate,
};
}

Expand Down Expand Up @@ -737,4 +740,9 @@ export class NgDataTableComponent {
getRange(size: number): number[] {
return Array.from({ length: size }, (_, index) => index + 1);
}

toggleNestedTable(index: number, event: Event) {
event.stopPropagation();
this.filterItems[index].showNested = !this.filterItems[index].showNested;
}
}
Loading