MatSort: the name of the property is not the same as matColumnDef -> causing issues

Is it possible to use matSort in an Angular table to sort a column where the property name differs from the matColumnDef?

<ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>TEST</th>
      <td mat-cell *matCellDef="let box"> {{box.input.name}} </td>
</ng-container>

Answer №1

Found the solution by implementing the changes at the following link

Therefore, made the adjustment from:

matColumnDef="name"

to:

matColumnDef="input.name"

Also, added the following entry in the code:

public displayedLoadingPointColumns: string[] = ['input.name', ... 

Inserted this method into the .ts file:

sortColumn($event: Sort): void {
    this.dataSource.sortingDataAccessor = (item, property) => {
      switch (property) {
        case 'input.name': {
          return item.input.name;
        }
        default: {
          return item[property]; }
      }
    };
}

In the HTML file, the implementation is as follows:

<table mat-table [dataSource]="this.dataSource" matSort (matSortChange)="sortColumn($event)">

  <ng-container matColumnDef="input.name">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>Title</th>
      <td mat-cell *matCellDef="let whatevet"> {{whatever.input.name}}</td>
  </ng-container>
...

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

Automatically forwarding to another page in Angular 4 due to idle time

Is it possible to implement a timeout feature for inactivity on a webpage? For example, if a user is idle for 20 seconds without interacting with the page, can we automatically redirect them to the home screen? I've been struggling to get this functi ...

An error was encountered when attempting to proxy the request /api/v0/dataservice/cluster/clusters from localhost:4300 to http://localhost:30510. The connection was refused (ECONNREFUSED)

I recently encountered an issue while working on my Angular 6 application. I attempted to fix vulnerabilities by running npm audit fix and npm audit fix --force, but this resulted in my application not compiling or working properly. To resolve this, I ende ...

When Ionic Angular app's IonContent scroll element returns an incorrect scrollTop value after navigation completes, what might be the reason behind this unexpected behavior?

In my quest to scroll the ion-content component to the top upon navigating to the page from certain selected pages, I have implemented a solution using the router's NavigationEnd events. However, I have encountered an issue where the IonContent's ...

Implementation of Asp.Net core identity combined with Angular 2

Recently, I developed a web-app using Asp.Net with angular2. To kickstart the project, I utilized generator-aspnetcore-spa. Now, my next step is to integrate identity management into the application. After some consideration, I have decided to go with Asp ...

What is the best way to monitor updates made to a function that utilizes firestore's onSnapShot method?

I am currently working with the following function: public GetExercisePosts(user: User): ExercisePost[] { const exercisePosts = new Array<ExercisePost>(); firebase.firestore().collection('exercise-posts').where('created-by&apo ...

Encountering a 404 error with Angular 6 routing after refreshing the page when using an Nginx proxy

I currently have my angular application running within a docker container, exposed on port 83. Additionally, I have a separate spring-boot rest app running inside another docker container, exposed on port 8083. On the host server, there is an Nginx server ...

Difficulty encountered when trying to show collapse/expand symbol using *ngFor in a mat-expansion-panel within Angular

Is it possible to have a customized icon for collapsing and expanding just the first header in a nested array, without triggering all headers? How can I separate the control so that only the 1st header expands when clicked? Check out this StackBlitz link ...

Issue: Unrecognized parameter: standalone while attempting to create a standalone Angular component using the Ionic CLI

Every time I attempt to create a standalone component using the Ionic CLI, an error pops up with the message below: $ ionic g c someComponent --standalone > ng generate component someComponent --standalone --project=app Error: Unknown argument: standalo ...

Automatically identify the appropriate data type using a type hint mechanism

Can data be interpreted differently based on a 'type-field'? I am currently loading data from the same file with known type definitions. The current approach displays all fields, but I would like to automatically determine which type is applicab ...

Create a Jest test environment with MongoDB and TypeScript, following the guidance provided in the Jest documentation

While attempting to set up a simple test file following the jest documentation, I encountered several linter errors: https://i.sstatic.net/bAPjC.png connection: The type 'Promise<MongoClient> & void' is missing properties such as &apo ...

What could be causing Next.js to re-render the entire page unnecessarily?

As a newcomer to Next.js, I am trying to develop an app where the header/navbar remains fixed at all times. Essentially, when the user navigates to different pages, only the main content should update without refreshing the navbar. Below is the code I have ...

How to securely authenticate with Spring using end user credentials in an Angular application

I currently have a set of RESTful web services that are supported by Spring Boot. These services are secured with basic HTTP authentication. I am working on developing an Angular2 front end, which will be hosted on a separate server. My goal is for the fr ...

Tips on connecting an Angular web application with Google authentication

Hello, I am exploring the Google Cloud Platform for the first time and need help with implementing Google sign-in on my Angular web application. I have searched for code solutions but haven't found anything useful yet. Can anyone recommend any documen ...

Transition from using ReactDOM.render in favor of asynchronous callback to utilize createRoot()

Is there a React 18 equivalent of this code available? How does it handle the asynchronous part? ReactDOM.render(chart, container, async () => { //code that styles some chart cells and adds cells to a worksheet via exceljs }) ...

My postman is successfully uploading image files, but for some reason, my code isn't cooperating. Are there any adjustments that need to be made?

While attempting to upload an image file with form data in Angular, I encountered a discrepancy in behavior between Postman and my project. In Postman, under the headers section, I have configured the following: Content-Type: multipart/form-data, token: ...

Angular - CSS Grid - Positioning columns based on their index values

My goal is to create a CSS grid with 4 columns and infinite rows. Specifically, I want the text-align property on the first column to be 'start', the middle two columns to be 'center', and the last column to be 'end'. The cont ...

What is the reason for Object.keys not returning a keyof type in TypeScript?

Wondering why Object.keys(x) in TypeScript doesn't return the type Array<keyof typeof x>? It seems like a missed opportunity as Object.keys outputs that by default. Should I report this on their GitHub repo, or should I just submit a pull reques ...

Creating Angular component in nx workspace without spec.ts file

My goal is to apply this change throughout the entire project. The challenge is that, unlike an Angular CLI project, there isn't an angular.json file available, only a project.json one. After reading through this answer, I attempted to add some confi ...

Guide on transferring the token and user information from the backend to the front-end

Here is the code from my userservice.ts file export class UserService { BASE_URL = "http://localhost:8082"; constructor(private httpClient:HttpClient) {} public login(loginData:any){ return this.httpClient.post(this.BASE_URL+"/au ...

Angular 9 and Bootstrap 4 combined in a row featuring up to 2 items maximum

Here's the HTML I'm working with: <div class="row"> <div formArrayName="addresses" *ngFor="let address of addressesFormArr.controls; let i = index" [formGroupName]="i"> <div *ngIf="i % 2 === 0" class="col-auto"> ...