简体   繁体   English

Kendo Grid中的“按日期排序”列用于不考虑AM / PM的角度

[英]Sorting on Date column in Kendo Grid for angular not considering AM/PM

I have a Kendo grid for angular in my component which is populated with data based on a pre-defined model. 我的组件中有一个用于角度的Kendo网格,该网格中填充了基于预定义模型的数据。 I am sorting the grid on a 'Date' field (StartTime). 我在“日期”字段(StartTime)上对网格进行排序。 While sorting, the AM/PM is not taken into consideration as can be seen in the screenshot below. 排序时,未考虑AM / PM,如下面的屏幕截图所示。

UI上显示的StartTime列的片段

The highlighted date should ideally be the third one in the sorting order. 理想情况下,突出显示的日期应该是排序顺序中的第三个日期。

Following are the relevant code snippets: 以下是相关的代码段:

Model: 模型:

export interface Summary {
...
StartTime: Date;
...
}

Sort descriptor: 排序描述符:

public sort: SortDescriptor[] = [{
field: 'StartTime',
dir: 'asc' 
}];

This statement is called while loading the grid: 加载网格时将调用以下语句:

this.gridData = orderBy(this.gridData, this.sort);

What am I missing here? 我在这里想念什么? How can I make the grid sort take AM/PM into consideration? 如何使网格排序考虑AM / PM?

Any help is greatly appreciated. 任何帮助是极大的赞赏。

The Grid data items need to contain actual JavaScript Date Objects (as opposed to string representations) so that the built-in Grid formatting, sorting and filtering functionalities can work as expected: Grid数据项需要包含实际的JavaScript Date对象(而不是字符串表示形式),以便内置的Grid格式化,排序和过滤功能可以按预期工作:

DOCS DOCS

If the data comes serialized from a remote service, it needs to be mapped such that all date strings are converted to actual dates, otherwise they will be sorted like strings. 如果数据是从远程服务序列化的,则需要对其进行映射,以便将所有日期字符串都转换为实际日期,否则它们将像字符串一样进行排序。

Here is an example where the data contains actual dates and they are sorted as expected: 这是一个示例,其中数据包含实际日期,并且按预期顺序对其进行了排序:

EXAMPLE

{
        "ProductID": 1,
        "ProductName": "Chai",
        "SupplierID": 1,
        "CategoryID": 1,
        "QuantityPerUnit": "10 boxes x 20 bags",
        "UnitPrice": 18,
        "UnitsInStock": 39,
        "UnitsOnOrder": 0,
        "ReorderLevel": 10,
        "Discontinued": false,
        "Category": {
            "CategoryID": 1,
            "CategoryName": "Beverages",
            "Description": "Soft drinks, coffees, teas, beers, and ales"
        },
        "FirstOrderedOn": new Date(2018, 4, 2, 18, 46, 53)
    }

<kendo-grid-column field="FirstOrderedOn" title="First Ordered On"
      width="240" filter="date" 
      format="{0:MM/dd/yyyy hh:mm:ss a}">
    </kendo-grid-column>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM