One of the tables in my database is called Job:
name nvarchar(50)
id int
description nvarchar(50)
enabled bit
date_modified datetime
user nvarchar(50)
Here is the corresponding class structure:
public class Job {
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool Enabled { get; set; }
public DateTime DateModified { get; set; }
public string User { get; set; }
}
Currently, I am working on an application using Angular and TypeScript. I have encountered a problem while trying to display data:
I am utilizing the ui-grid component from Angular for the grid layout. The column definitions are as follows:
columnDefs: [
{
field: 'id',
defaultFilter: FilterOperator.EQU,
sort: {
direction: this.uiGridConstants.DESC,
priority: 0,
},
type: 'number'
},
{ field: 'name', defaultFilter: FilterOperator.LIKE, sort: null },
{ field: 'description', defaultFilter: FilterOperator.LIKE, sort: null },
{ field: 'enabled', filter: { type: 'select', selectOptions: [{ value: true, label: 'True' }, { value: false, label: 'False' }] } },
{ field: 'user', defaultFilter: FilterOperator.LIKE, sort: null },
{ field: 'date_modified', type: 'date', enableFiltering: false, sort: null, cellTemplate: '<div>{{row.entity.dateModified | date:\'dd/MM/yyyy hh:mm:ss\'}}</div>' },
{ field: 'action', enableFiltering: false, enableSorting: false, sort: null, cellTemplate: `${this.baseUrl}app/automaticAction/listActionsTemplate.html` }
]
The issue I am facing is related to sorting the 'date modified' column. To sort it correctly, I need the field property value to match the database column (date_modified), but for displaying data, I need to use the class property (dateModified). Is there a way to extend or modify the column definitions to specify the desired column for sorting? I am currently using a workaround with celltemplate, but I am open to better solutions.