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.

Custom comparator + columns width

See original GitHub issue

I’m submitting a … (check one with “x”)

[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’s possible to add a custom comparator for a column in the class like that :

columns = [
    { name: 'Company', comparator: this.companyComparator.bind(this) },
    { name: 'Name', sortable: false },
    { name: 'Gender', sortable: false }
  ];

It’s also possible to fixe the columns width in the template like that :

<ngx-datatable
    [columnMode]="'force'"
    ...
    [rows]="rows">
    <ngx-datatable-column name="Name" [width]="100"></ngx-datatable-column>
     ...
</ngx-datatable>

But it seems impossible to set the column width in the class or to set the comparator in the template.

Expected behavior To be able to set both the columns width and the comparator in the class like that :

columns = [
    { name: 'Company', width: '100', comparator: this.companyComparator.bind(this) },
    { name: 'Name', width: '300', sortable: false },
    { name: 'Gender', width: '300', sortable: false }
  ];

And to be able to set both the columns width and the comparator in the template like that :

<ngx-datatable
    [columnMode]="'force'"
    ...
    [rows]="rows">
    <ngx-datatable-column name="Name" [width]="100" comparator="customComparator()"></ngx-datatable-column>
     ...
</ngx-datatable>

Reproduction of the problem

What is the motivation / use case for changing the behavior? I need to set width because some columns are just a short number, others are long string. Furthermore, I also need to set a custom comparator because one of my columns contains date.

Please tell us about your environment: Win 10

  • Table version: 0.8.x 9.1.0

  • Angular version: 2.0.x 4.0.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] all

  • Language: [all | TypeScript X.X | ES6/7 | ES5] TypeScript 2.2.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
sheiidancommented, Apr 25, 2018

@Ryan-Haines , here is a simple comparator example: https://stackblitz.com/edit/angular-lsjnep

5reactions
sheiidancommented, May 26, 2017

You can set custom comparator in this way: In your component ts file: customComparator = (a, b) => … And in your template file: [comparator]=“customComparator”

Read more comments on GitHub >

github_iconTop Results From Across the Web

column-width - CSS: Cascading Style Sheets - MDN Web Docs
The column-width CSS property sets the ideal column width in a multi-column layout. The container will have as many columns as can fit ......
Read more >
How to add Custom Width to Table Columns?
You need to provide Column Width to the Header Columns. This width will be adopted by all the columns below.
Read more >
JavaFx - TableView: How to use custom Comparator<T> for ...
I'm implementing a file-listview with three columns, so far. Each of type java.nio.file.Path . For the name column, I wrote a Comparator<Path> which...
Read more >
Inputs - ngx-datatable - GitBook
The width of the column by default in pixels. Default value: 150 ... Custom sort comparator, used to apply custom sorting via client-side....
Read more >
Custom Sorting - Thinkster.io
We can define and use a custom comparator for sorting the grid. ... column definitions { headerName: "Amount", field: "amount", width: 140, comparator: ......
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