I used a material table as a reusable component. I call it in other component as followed.
class UserTable {
name: string;
vehicleId: number;
garageId: number;
}
tableColumns: Array<Column> = [
{
columnDef: 'name',
header: 'Name',
cell: (element: Record<string, unknown>) => `${element['name']}`
},
{
columnDef: 'vehicleId',
header: 'Vehicle',
cell: (element: Record<string, unknown>) => {
const vehicle = this.vehicleList.find(vehicles => vehicles.id === element['vehicleId']);
return vehicle?.name;
}
},
{
columnDef: 'garageId',
header: 'Garage',
cell: (element: Record<string, unknown>) => {
const garage = this.garageList.find(garages => garages.id === element['garageId']);
return garage?.name;
}
}
];
the User class
class User implements IUser {
id: number;
name: string;
description: string;
vehicleId: number;
garageId: number;
}
I need to display name, vehicle Name, garage in the table. to display vehicle name, i used above code. It works, but give console error 'Cannot read properties of undefined (reading 'find')' and can't visible the garage name also.
what can i do for that?