date.getTime不是一个功能extJS datefield列 [英] date.getTime is not a functioin extJS datefield column

查看:79
本文介绍了date.getTime不是一个功能extJS datefield列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网格中的日期过滤器出现错误。

During the date filter in grid I am getting this error.

Uncaught TypeError: date.getTime is not a function
    at Object.clearTime (ext-all-rtl-debug.js?_dc=1591679946477:6514)
    at constructor.convertDateOnly [as _convert] (ext-all-rtl-debug.js?_dc=1591679946477:237750)
    at constructor.getCandidateValue (ext-all-rtl-debug.js?_dc=1591679946477:45385)
    at constructor.= [as _filterFn] (ext-all-rtl-debug.js?_dc=1591679946477:45406)
    at constructor.filter (ext-all-rtl-debug.js?_dc=1591679946477:45222)
    at ext-all-rtl-debug.js?_dc=1591679946477:45143
    at constructor.onCollectionRefresh (ext-all-rtl-debug.js?_dc=1591679946477:82919)
    at constructor.updateSource (ext-all-rtl-debug.js?_dc=1591679946477:83983)
    at constructor.setter [as setSource] (ext-all-rtl-debug.js?_dc=1591679946477:11193)
    at constructor.onFilterChange (ext-all-rtl-debug.js?_dc=1591679946477:83515)

这是我的列防御。

"dataIndex" : "date",
            "text" : " Date",
            "minWidth" : 120.0,
            "xtype" : "datecolumn",
            "renderer" : "renderDate",
            "filter" : {
                "type" : "date"

  }

这是renderDate方法。

here is renderDate method.

renderDate : function(val){
        debugger;
        val = new Date(val)
        val = Ext.Date.format(val,'d-M-Y H:i:s T'); 
        return val;
    },

有人可以帮助我解决这个问题以及如何解决它。

Can anybody help me about this problema nd how to solve it. Thanks is advamce.

这是我的网格存储:

Ext.define("MyAPp.store.base.GridStore", {
    extend: "Ext.data.Store",
    alias:"widget.tGridStore",
    requires: ["Ext.data.proxy.Rest"],
    model: Ext.create('Ext.data.Model', {
        fields: [
            { name: 'name', type: 'String' },

        ]
    }),
    autoLoad: false,
    remoteSort : false,
    remoteFilter: false,
    proxy: {
        type: 'ajax',
        url: 'someURLa',
        actionMethods:{
            read:'POST'
        },  
        reader: {
            type: 'json',
            rootProperty: "data",
            totalProperty: "TotalCount"
        }
    }
});


推荐答案

问题不在 renderDate 函数,否则它的函数名称应显示在堆栈跟踪中。

The problem is not in the renderDate function, its function name should otherwise show up in the stack trace.

堆栈跟踪提示过滤器。问题的原因似乎是您将 date 类型的过滤器应用于支持网格列的商店的模型字段。所述过滤器要求后备模型字段包含javascript日期对象(或null),而不包含(日期可解析的)非空字符串。加载到存储中的至少一条记录在 date 字段中没有包含有效的javascript日期对象。

The stack trace hints to filters. The cause of the problem seems to be that you apply a filter of type date to the model field on the store backing the grid column. Said filter requires the backing model field to contain javascript date objects (or null), not (date-parseable) non-empty strings. At least one record loaded into the store does not contain a valid javascript date object in the date field.

您必须确保模型字段的配置将 date 字段定义为类型 date ,并且您提供了正确的 dateFormat ,以便商店在加载时将日期字符串正确地转换为javascript日期对象:

You have to ensure that the model fields config defines the date field as type date, and that you provide the correct dateFormat so that the date strings are correctly converted to javascript date objects by the store on load:

fields: [{
    name: "date",
    type: "date",
    dateFormat: "Y-m-d H:i:s" // whatever the format is in which you expect the date string from the backend
}]

如果该解决方案尝试无法为您解决,请发布商店/模型定义代码以及您加载到商店中的数据。

If that solution attempt does not solve it for you, please post your store/model definition code and the data you load into the store.

注意, datecolumn 允许您提供日期显示格式为 format 配置,不需要自定义渲染器。

On a side note, the datecolumn allows you to provide the date display format as format config, no custom renderer required.

简而言之,store / model字段( type: date dateFormat 需要将您从后端获取的任何日期字符串转换为javascript日期对象;过滤器(类型:日期 )然后仅适用于javascript日期对象;然后最后一列( xtype: datecolumn format 知道如何将javascript日期对象转换回可读格式(通常可以与后端传输到UI的格式不同)。

In short, the store/model field (type: "date") dateFormat is needed to transform whatever date string you get from the backend, into a javascript date object; the filter (type: "date") then works with a javascript date object only; and then finally the column (xtype: "datecolumn") format knows how to transform that javascript date object back to a human-readable format (which can be and usually is different from the format that the backend transmits to the UI).

这篇关于date.getTime不是一个功能extJS datefield列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆