Skip to content

Commit faae6c0

Browse files
committed
Create an id property, this new property will be used as unique to indentify each column instead of "data"
1 parent f789275 commit faae6c0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-datatables",
3-
"version": "16.0.0",
3+
"version": "16.0.1",
44
"description": "Angular directive for DataTables",
55
"scripts": {
66
"build": "npm run clean && npm run compile && npm run bundles && npm run schematics:build",

src/angular-datatables.directive.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export class DataTableDirective implements OnDestroy, OnInit {
7575
reject('Both the table and dtOptions cannot be empty');
7676
return;
7777
}
78+
79+
// Set a column unique
80+
resolvedDTOptions.columns.forEach((col: ADTColumns, i: number) => col.id = i);
81+
7882
// Using setTimeout as a "hack" to be "part" of NgZone
7983
setTimeout(() => {
8084
// Assign DT properties here
@@ -108,7 +112,7 @@ export class DataTableDirective implements OnDestroy, OnInit {
108112
const pipe = el.ngPipeInstance;
109113
const pipeArgs = el.ngPipeArgs || [];
110114
// find index of column using `data` attr
111-
const i = columns.filter(c => c.visible !== false).findIndex(e => e.data === el.data);
115+
const i = columns.filter(c => c.visible !== false).findIndex(e => e.id === el.id);
112116
// get <td> element which holds data using index
113117
const rowFromCol = row.childNodes.item(i);
114118
// Transform data with Pipe and PipeArgs
@@ -125,7 +129,7 @@ export class DataTableDirective implements OnDestroy, OnInit {
125129
colsWithTemplate.forEach(el => {
126130
const { ref, context } = el.ngTemplateRef;
127131
// get <td> element which holds data using index
128-
const i = columns.filter(c => c.visible !== false).findIndex(e => e.data === el.data);
132+
const i = columns.filter(c => c.visible !== false).findIndex(e => e.id === el.id);
129133
const cellFromIndex = row.childNodes.item(i);
130134
// reset cell before applying transform
131135
$(cellFromIndex).html('');

src/models/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export interface ADTSettings extends DataTables.Settings {
44
columns?: ADTColumns[];
55
}
66
export interface ADTColumns extends DataTables.ColumnSettings {
7+
/** Define a column index */
8+
id?: number;
79
/** Set instance of Angular pipe to transform the data of particular column */
810
ngPipeInstance?: PipeTransform;
911
/** Define the arguments for the tranform method of the pipe, to change its behavior */

0 commit comments

Comments
 (0)