question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override [column] property with ngx-datatable-column

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:12
  • Comments:5

github_iconTop GitHub Comments

6reactions
Fortidudecommented, Nov 9, 2017

Just started with ngx-datatable and I’m suprised there is no such a feature… whole point on column orders are pointless 😕

2reactions
0x62commented, Nov 1, 2017

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<DataTableColumnDirective>) {
   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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to change the ngx-datatable-column name?
The columns (header) names are numbers. Is there any way that I can edit those names in view? After search I could not...
Read more >
swimlane/ngx-datatable - Gitter
If you override column templates, it only shows those specific columns. Any way to give custom templates for only a few columns and...
Read more >
ngx-datatable - Angular component for presenting large and ...
Column. Flex; Toggling; Fixed; Force; Pinning; Reorder. Summary Row. Simple; Custom Template; Server-side paging; Inline HTML. Fluid Row Heights Source.
Read more >
How To Use Ngx-Datatable To Show The Data In Grid ...
... <ngx-datatable-column name="Order No" prop="order_number"></ngx-datatable-column>; <ngx-datatable-column name="Action" widht="600"> ...
Read more >
swimlane/ngx-datatable@20.1.0
property ɵdir. static ɵdir: i0.ɵɵDirectiveDeclaration<. DataTableColumnDirective,. 'ngx-datatable-column',. never,. {. name: 'name';.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found