Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Create an id property, this new property will be used as unique to in… #1750

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.0",
"version": "16.0.1",
"description": "Angular directive for DataTables",
"scripts": {
"build": "npm run clean && npm run compile && npm run bundles && npm run schematics:build",
Expand Down
8 changes: 6 additions & 2 deletions src/angular-datatables.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ 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);

// Using setTimeout as a "hack" to be "part" of NgZone
setTimeout(() => {
// Assign DT properties here
Expand Down Expand Up @@ -108,7 +112,7 @@ export class DataTableDirective implements OnDestroy, OnInit {
const pipe = el.ngPipeInstance;
const pipeArgs = el.ngPipeArgs || [];
// find index of column using `data` attr
const i = columns.filter(c => c.visible !== false).findIndex(e => e.data === el.data);
const i = columns.filter(c => c.visible !== false).findIndex(e => e.id === el.id);
// get <td> element which holds data using index
const rowFromCol = row.childNodes.item(i);
// Transform data with Pipe and PipeArgs
Expand All @@ -125,7 +129,7 @@ export class DataTableDirective implements OnDestroy, OnInit {
colsWithTemplate.forEach(el => {
const { ref, context } = el.ngTemplateRef;
// get <td> element which holds data using index
const i = columns.filter(c => c.visible !== false).findIndex(e => e.data === el.data);
const i = columns.filter(c => c.visible !== false).findIndex(e => e.id === el.id);
const cellFromIndex = row.childNodes.item(i);
// reset cell before applying transform
$(cellFromIndex).html('');
Expand Down
2 changes: 2 additions & 0 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export interface ADTSettings extends DataTables.Settings {
columns?: ADTColumns[];
}
export interface ADTColumns extends DataTables.ColumnSettings {
/** Define a column index */
id?: number;
/** 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