Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to format the value of a grid column as USD $ currency? #5951

Closed
brookhutchinson opened this issue Oct 9, 2019 · 5 comments
Closed

How to format the value of a grid column as USD $ currency? #5951

brookhutchinson opened this issue Oct 9, 2019 · 5 comments

Comments

@brookhutchinson
Copy link

brookhutchinson commented Oct 9, 2019

Question

How do I format the value of a grid column as USD $ currency?

For some reason every other row in the grid is not immediately displaying the column value. Instead a user has to hover over the missing row column value and then the value displays.

  • igniteui-angular version: 8.2.2
  • browser: Google Chrome Version 77.0.3865.90 (Official Build) (64-bit)

Here is the code that I am using for my grid column

<igx-column field="annual_credit_value" header="Annual Value" width="100" [dataType]="'number'" [disableHiding]="false" [disablePinning]="false" [filterable]="true" [movable]="false" [resizable]="true" [sortable]="true"> <ng-template let-value> {{ value | currency: 'USD': 'symbol': '1.0-0' }} </ng-template> </igx-column>

@brookhutchinson brookhutchinson changed the title How to format grid column as USD $ currency? How to format the value of a grid column as USD $ currency? Oct 9, 2019
@ddincheva
Copy link
Contributor

ddincheva commented Oct 9, 2019

Hello @brookhutchinson ,
In order to be able to define a custom cell template you need to add the following directive:
IxgCell is used for default cell template;
IgxCellEditor is used when the cell is in edit mode;
You can read more detailed information in our official documentation. Also you can take a look at the code of this sample;
Please check them out, and let us know if you have any concerns

@brookhutchinson
Copy link
Author

brookhutchinson commented Oct 9, 2019

You mention that I need to add the IgxCell directive to a column that I want to format as currency. The second column in your sample named "Price" looks like it is formatting the value as currency, but does not have an igxCell directive or a <ng-template> defined. Help me understand what I am missing.

@ddincheva
Copy link
Contributor

If you want to add any custom mark up, provide some additional logic or to format the cell value, you can define a custom cell template. Like in the snippet below:

<igx-column field="TestField" header="Value" width="100" [dataType]="'number'"> 
  <ng-template IgxCell let-cell='cell'>
      <div class='sampleClass'> // this is just sample. You can omit the div in your use case
        $ {{ cell.value }} 
     </div>
  </ng-template> 
</igx-column>

If you just need to format the cell value you can just use the column formatter property, as you see in the sample that I linked below.
You can use either approach you decide for this use case.

@brookhutchinson
Copy link
Author

How can I format the value of a column to $ USD currency with no numbers after decimal place and allow the user to be able to click a column header to sort the currency values in ascending order or descending order?

@rkaraivanov
Copy link
Member

@brookhutchinson

As mentioned above, you can use either the cell template functionality or the column formatter property. You can see them in action here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants