使用 YUI 的日期格式(mm/dd/yyyy HHMMSS)排序问题

发布于 2024-09-27 13:20:21 字数 111 浏览 0 评论 0原文

我无法使用 YUI YAHOO.widget.DataTable.formatDate 对日期格式(mm/dd/yyyy HHMMSS)的列进行排序

请帮助我解决这个问题

问候

I won't be able to sort the column which has the date format(mm/dd/yyyy HHMMSS) by using YUI YAHOO.widget.DataTable.formatDate

Please help me out on this problem

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪冰清 2024-10-04 13:20:21

好吧,来自 YUI dataTable

它希望以本机 JavaScript 类型保存数据。例如,日期应该是 JavaScript Date 实例,而不是像“4/26/2005”这样的字符串以便正确排序。因此,数据表中保存的数据类型(例如,字符串、数字、日期等)决定排序算法,而不是列中定义的类型定义格式化程序属性。

这意味着格式化属性(用于以人类友好的格式显示数据)函数与排序算法无关

输入数据如何转换???

当数据进入数据表时转换数据类型通过数据源响应架构的字段数组中的解析器属性启用

您的问题不清楚。我想您的数据为 mm/dd/yyyy HHMMSS。如果是这样,您需要使用 dataSource 的解析器属性转换为纯 JavaScript 日期(如上所述)

myDataSource.responseSchema = {
    fields: [
        {key:"birthDate", parser:function(data) {
            // Convert to native JavaScript objects right here        
        }}
    ]
}

Well, from YUI dataTable

It expects to hold data in native JavaScript types. For instance, a date is expected to be a JavaScript Date instance, not a string like "4/26/2005" in order to sort properly. Therefore, the type of the data (e.g., String, Number, Date, etc.) held in the dataTable determines the sort algorithm, not the type as defined in your Column definition formatter property.

Which implies the formatter property (used to show data in a human-friendly format) function has nothing to do with the sorting algorithm

How does input data is converted ???

Converting data types as data comes into your dataTable is enabled through the parser property in the fields array of your DataSource's responseSchema

You question is not clear. I suppose your data comes as mm/dd/yyyy HHMMSS. If so, you need to convert to a plain JavaScript Date (as said above) by using dataSource's parser property

myDataSource.responseSchema = {
    fields: [
        {key:"birthDate", parser:function(data) {
            // Convert to native JavaScript objects right here        
        }}
    ]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文