Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dlascarez committed Sep 18, 2023
1 parent faae6c0 commit 4276da6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-datatables",
"version": "16.0.1",
"version": "16.0.0",
"description": "Angular directive for DataTables",
"scripts": {
"build": "npm run clean && npm run compile && npm run bundles && npm run schematics:build",
Expand Down
21 changes: 19 additions & 2 deletions src/angular-datatables.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ export class DataTableDirective implements OnDestroy, OnInit {
reject('Both the table and dtOptions cannot be empty');
return;
}

// Set a column unique
resolvedDTOptions.columns.forEach((col: ADTColumns, i: number) => col.id = i);
resolvedDTOptions.columns.forEach(col => {
if ((col.id ?? '').trim() === '') {
col.id = this.getColumnUniqueId();
}
});

// Using setTimeout as a "hack" to be "part" of NgZone
setTimeout(() => {
Expand Down Expand Up @@ -142,4 +146,17 @@ export class DataTableDirective implements OnDestroy, OnInit {
this.renderer.appendChild(cellFromIndex, instance.rootNodes[0]);
});
}

private getColumnUniqueId(): string {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

for (let i = 0; i < 6; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters.charAt(randomIndex);
}

return result.trim();
}

}
4 changes: 2 additions & 2 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export interface ADTSettings extends DataTables.Settings {
columns?: ADTColumns[];
}
export interface ADTColumns extends DataTables.ColumnSettings {
/** Define a column index */
id?: number;
/** Define the column's unique identifier */
id?: string;
/** Set instance of Angular pipe to transform the data of particular column */
ngPipeInstance?: PipeTransform;
/** Define the arguments for the tranform method of the pipe, to change its behavior */
Expand Down

0 comments on commit 4276da6

Please sign in to comment.