Ngx-datatable: Override [column] property with ngx-datatable-column

Created on 1 Nov 2017  路  5Comments  路  Source: swimlane/ngx-datatable

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior
It is impossible to use both [columns]="" and ngx-datatable-column templates at the same time. I have a standard list of default columns for each my models, which I use to populate [columns], however sometimes I want to display the data as something other than the value (for example, displaying a date in a different locale). In order to do this, I have to redefine all my columns using ngx-datatable-column, as if you use both, it will only use columns defined using inline templates.

Expected behavior
I would like to be able to provide an object defining columns, and additionally override how any of these columns are displayed using ngx-datatable-column. What should be displayed is all columns provided by the object, and where any columns are defined both in the object and as an inline template, the inline template is used as an override.

Reproduction of the problem

What is the motivation / use case for changing the behavior?
Many users will need to change how data is displayed in the table, and keeping all your columns as templates is inefficient.

Please tell us about your environment:
N/A

  • Table version: 10.2.1

  • Angular version: 4.3.6

  • Browser: All

  • Language: TS

Most helpful comment

Just started with ngx-datatable and I'm suprised there is no such a feature... whole point on column orders are pointless :/

All 5 comments

I've created this modification in my local version, which allows me to define as an object, template, or both. Templates will always override the object, and keep the same order. Any templates which aren't included in the object are appended.

src/components/datatable.component.ts:545

```
@ContentChildren(DataTableColumnDirective)
set columnTemplates(val: QueryList) {
this._columnTemplates = val;

if (val) {
  // only set this if results were brought back
  const arr = val.toArray();

  if (arr.length) {

    let existingCols = this._internalColumns || [];
    const translated = translateTemplates(arr);

    for (const i in existingCols) {
      for (let j = 0; j < translated.length; j++) {
        if (translated[j].name === existingCols[i].name) {
          existingCols[i] = translated[j];
          translated.splice(j, 1);
          break;
        }
      }
    }

    existingCols = existingCols.concat(translated);

    // translate them to normal objects
    this._internalColumns = existingCols;
    setColumnDefaults(this._internalColumns);
    this.recalculateColumns();
  }
}

}
```

If this is of interest as a feature, I can submit a pull request.

I have been looking for something like this. I feel this will be a good feature. Hopefully, others also feel the same. Thanks.

Just started with ngx-datatable and I'm suprised there is no such a feature... whole point on column orders are pointless :/

I cannot +1 this more.

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lautarobock picture lautarobock  路  3Comments

WA-WilliamKrieg picture WA-WilliamKrieg  路  3Comments

Matthi0uw picture Matthi0uw  路  3Comments

paritosh64ce picture paritosh64ce  路  3Comments

Csirme picture Csirme  路  3Comments