Upgrade to Primeng 4.3 to easily convert column values from 'S' and 'N' to 'Yes' and 'No' in your Datatable

These are the columns I have:

this.columns = [
   { field: 'acronym', header: 'Acronym', sortable: true },
   { field: 'name', header: 'Name', sortable: true },
   { field: 'commonUserName', header: 'Credentials', sortable: true },
   { field: 'scope', header: 'Scope', sortable: true },
   { field: 'transversal', header: 'Transversal', sortable: true },
   { field: 'startDate', header: 'Start Date', sortable: true },
   { field: 'suspendDate', header: 'Suspend Date', sortable: true },
];

The HTML element p-dataTable is structured as follows:

<div style="margin-bottom: 1.54em" *ngIf="!apps.error">
    <p-dataTable #appsTable [value]="apps.content"...>
        <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [sortable]="col.sortable">
        </p-column>
    </p-dataTable>
</div>

This configuration results in a table that looks like the following link:

https://i.sstatic.net/Daz3G.png

In the table, values are displayed as either "S" or "N". I want to display "Yes" when the value is "S" and "No" when the value is "N".

The data model consists of an array of objects with the following properties:

export interface ApplicationUser {
    acronym: string;
    code: string;
    commonUserName: string;
    description: string;
    name: string;
    transversal: string;
}

Do you have any suggestions on how to achieve this?

Answer №1

Utilize the template columns for defining the specified columns

<p-column *ngFor="let col of cols" field="col.field" header="col.header">
    <ng-template let-col let-data="rowData" let-ri="rowIndex" pTemplate="body">
        <span>{{col.field=='transversal'?data[col.field]=='S'?'Yes':'No':data[col.field]}}</span>
    </ng-template>
</p-column>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: The function createImageUrlBuilder from next_sanity__WEBPACK_IMPORTED_MODULE_0__ is not defined as a valid function

Having some trouble with my Next.js TypeScript project when integrating it with sanity.io. I keep getting an error saying that createImageUrlBuilder is not a function. See screenshot here Here is the code from my sanity module ...

Combining Angular 1.3.4 and Angular 2 - A comprehensive guide

Currently, I have an application built on Angular 1.3.4 and my goal is to gradually transition it to Angular 2, module by module. For instance, if there are 5 modules on my webpage, I want to move one module to Angular 2 while keeping the other modules ru ...

Combining and mapping arrays in Javascript to form a single object

I am using the following firebase function this.sensorService.getTest() .snapshotChanges() .pipe( map(actions => actions.map(a => ({ [a.payload.key]: a.payload.val() }))) ).subscribe(sensors => { ...

Validating patterns in Angular without using a form

Seeking guidance on validating user input in Angular6 PrimeNG pInputText for a specific URL pattern, such as , possibly triggered on blur event. This particular field used to be part of a form but has since been relocated to a more complex 6-part form int ...

Creating a Typescript mixin function that accepts a generic type from the main class

I am working with the code snippet shown below: // Types found on https://stackoverflow.com/a/55468194 type Constructor<T = {}> = new (...args: any[]) => T; /* turns A | B | C into A & B & C */ type UnionToIntersection<U> = (U extend ...

The NbDatePicker does not display certain Spanish names

One issue I'm facing is with the Nb-DatePicker component in my project. I tried using {provide: LOCALE_ID, useValue: "es-MX"} in my app.component to display it in Spanish. However, when February, April, May, August, or December are selected, ...

Troubleshooting a Typescript typing problem within the map function for mixed types in a React

I have created two object types, Team and Position, which are both part of an array that I loop through in my react component. When I try to iterate over the array using the map function, I encounter the following errors: Here are some examples of the er ...

Guide on filtering FlatList Data in react native by selecting multiple categories from an array

User Interface Image I am looking to implement a filter functionality in the FlatList data based on top categories, where the filter button allows for multiple selections. The FlatList data is stored in the HotelData array, and the categories are also re ...

Is it necessary to ensure application readiness before proceeding with unit testing exports?

I've been facing a challenge while trying to utilize Jest for unit testing an express API that I've developed. The issue arises when the database needs to be ready before running the test, which doesn't seem to happen seamlessly. In my serve ...

I am looking to append a new value to an array within the state in React

development environment ・ react ・ typescript In this setup, state groups are stored as arrays. If you want to add a group to the array of groups when the onClickGroups function is called, how should you go about implementing it? interface ISearc ...

Inform the Angular2 Component regarding the creation of DOM elements that are placed outside of the

The Challenge In my Angular2 project, I am using Swiper carousel and building it with Webpack. However, Angular2 adds random attributes like _ngcontent-pmm-6 to all elements in a component. Swiper generates pagination elements dynamically, outside of Ang ...

Conceal the header and the navigation tabs at the bottom while scrolling - Ionic version 3

Is there a way to conceal the header and footer (tabs at the bottom) as the user begins scrolling down vertically and then bring back the tabs and header when scrolling back up? I would appreciate any tutorials or documentation guides. https://i.sstatic ...

What is the TypeScript syntax for indicating multiple generic types for a variable?

Currently working on transitioning one of my projects from JavaScript to TypeScript, however I've hit a roadblock when it comes to type annotation. I have an interface called Serializer and a class that merges these interfaces as shown below: interfa ...

Encountering a tsx-loader issue when integrating tsx with vuejs

I've been attempting to integrate TSX with Vuejs based on several blog posts, but I'm consistently encountering the error displayed below. I cloned a starter kit from GitHub and it worked fine, leading me to believe that there may be an issue wit ...

Experiencing Issues with Angular Service Worker - Outdated Build Persisting - Seeking Angular Resolution

A Revision to an Edit: The answer below clarifies the issue. Despite Angular SW working properly with hashing, there was a problem with the server re-hashing certain bundles, causing a mismatch between the client and server SW versions. Edit: Allow me t ...

When attempting to run npm run build for a Next.js application on an EC2 instance, it unexpectedly terminates on its own

While attempting to deploy my Next.js app on EC2, I encountered an issue where the npm run build command was being automatically killed. Suspecting it may be due to insufficient RAM, I switched to an instance type with 4GB of RAM (t3.medium), but the probl ...

What steps can be taken to implement jQuery within an Angular 15 npm package?

In my development process, I often create my own npm packages using Angular and Typescript. One of the packages I am currently working on is a PDF viewer service, which includes a file named pdf-viewer.service.ts with the following code: import { Behavior ...

Setting default parameters for TypeScript generics

Let's say I define a function like this: const myFunc = <T, > (data: T) => { return data?.map((d) => ({name: d.name}) } The TypeScript compiler throws an error saying: Property 'name' does not exist on type 'T', whic ...

Is the canActivate function causing a lag in the application? When is the appropriate time to invoke it?

I have an Angular application with a .NET Core backend. User authorization and identification are handled through Windows Active Directory. While everything is functional, I suspect that the app may be running slowly. Upon investigation, it seems that the ...

Sorting character values in TypeScript using ascending and descending order in a JSON array

In my dataset of homes, I have the following information: var homes = [ { "h_id": "3","city": "Dallas","state": "YYYY","zip": "75201","price": "162500" }, { "h_id": "4","city": "CA","state": "ZZZZ","zip": "90210","price": "319250" }, { "h ...