Challenges Encountered When Working with Date Fields in Kendo JS Grid

We are facing an unusual issue with the Kendo UI Grid on our production site.

Some users are experiencing date fields showing as null in Google Chrome, while they appear correctly in private browsing mode and other browsers like IE and MSEdge. We have been unable to reproduce the issue.

The code is outlined below. When exporting the grid to Excel, the date fields export properly, but when displaying them, they show as null

var dataSource = new kendo.data.DataSource({
    type: "odata-v4",
    transport: {
        read: {
            url: api + "/api/odata/Orders",
            dataType: "json"
        },

        parameterMap: function (options, type) {
            var paramMap = kendo.data.transports["odata-v4"].parameterMap.call(this, options, type);
            delete paramMap.$inlinecount;
            delete paramMap.$format;
            return paramMap;
        }
    },
    schema: {
        data: function (data) {

            return data.value;
        },
        total: function (data) {
            return data["@odata.count"];
        },
        model: {
            fields: {
                LINE_ID: { type: "string" },
                REQUESTED_DATE: { type: "datetime" },
                SCHEDULE_SHIP_DATE: { type: "datetime" },
                ACTUAL_SHIPMENT_DATE: { type: "datetime" },
                INVOICE_DATE: { type: "datetime" },
                INVOICE_NUMBER: { type: "string" },

            }
        }
    },
    pageSize: 10,
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true,
    sort: {
        field: "REQUESTED_DATE",
        dir: "desc"
    }
});

$("#grid").kendoGrid({
    toolbar: [
        { template: "<a role='button' class='k-button k-button-icontext k-grid-excel'><i class='fa fa-file-excel-o'></i> <span data-i18n='excel-export'>Excel Export</span></a>" },
        { template: "<input type='search' id='searchbox' class='k-input pull-right-not-xs' placeholder='Search...'  data-i18n='[placeholder]search'>" }
    ],
    excel: {
        fileName: "Orderdetails.xlsx",
        allPages: true,
        filterable: true
    },
    dataSource: dataSource,
    height: 480,
    autoBind: false,
    filterable: true,
    selectable: "row",
    sortable: true,
    reorderable: true,
    resizable: true,
    columnHide: onColumnChange,
    columnShow: onColumnChange,
    pageable: {
        refresh: true,
        pageSizes: true,
        buttonCount: 5
    },
    columnMenu: true,
    columns: [
        { field: "LINE_ID", width: 150, hidden: true, title: i18next.t("id") },

        {

            columns:
                [

                    { field: "REQUESTED_DATE", template: "#if(REQUESTED_DATE != null){# #=kendo.toString(kendo.parseDate(REQUESTED_DATE, 'yyyy-MM-dd'), 'MMM d, yyyy')#  #}#", minScreenWidth: 1200, width: 120, title: i18next.t("requested") },
                    { field: "SCHEDULE_SHIP_DATE", template: "#if(SCHEDULE_SHIP_DATE != null){# #=kendo.toString(kendo.parseDate(SCHEDULE_SHIP_DATE, 'yyyy-MM-dd'), 'MMM d, yyyy')#  #}#", minScreenWidth: 500, width: 120, title: i18next.t("scheduled") },
                    { field: "ACTUAL_SHIPMENT_DATE", template: "#if(ACTUAL_SHIPMENT_DATE != null){# #=kendo.toString(kendo.parseDate(ACTUAL_SHIPMENT_DATE, 'yyyy-MM-dd'), 'MMM d, yyyy')#  #}#", hidden: true, title: i18next.t("actual") },
                ],
            minScreenWidth: 1000,
            title: i18next.t("shipment-date")
        },
        { field: "INVOICE_DATE", template: "#if(INVOICE_DATE != null){# #=kendo.toString(kendo.parseDate(INVOICE_DATE, 'yyyy-MM-dd'), 'MMM d, yyyy')#  #}#", hidden: true, width: 150, title: i18next.t("invoice-date") },
        { field: "INVOICE_NUMBER", hidden: true, width: 150, title: i18next.t("invoice-number") }

    ]
});

In addition, we observed that after clearing browser history and cookies, the issue resolved itself. Moreover, we load the JS file appended with a datetime tick:

(//js/orders.js?v=1544691642371)

Update: All the dates format are coming as

2019-04-17T08:05:00-07:00
2018-11-22T08:05:22-08:00

Answer №1

Here are my recommendations:

  1. Investigate how the dates are returned from the endpoint using the browser's developer tools.
  2. Verify the model fields definitions, as 'datetime' may not be recognized in JavaScript. Consider changing them to 'date' as explained here.

The field type should be specified as "string", "number", "boolean", "date", or "object". The default is "string".

  1. Try removing column templates to ensure the dates are displayed correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine how the scale of a transform changes over time by calculating the function of elapsed time [ transform: scale(x, y

I am currently working on a container that can be expanded and collapsed simply by clicking on a chevron icon. The functionality to collapse or expand the container resides within a function called transformAnimation. This function code closely resembles t ...

The code to trigger the button with the ID 'Button' using Document.getElementById() is not executing the associated code-behind

Having just started coding in javascript/VB.NET, I am struggling to get my Button2 onClick event to work properly. The Code-Behind Click Event for Button1 in Page.aspx.vb: Protected Sub _lnbComments_Click(ByVal sender As Object, ByVal e As System.EventAr ...

Guide on how to use a JavaScript AJAX call to download a text file in Java

I am looking to implement a way to download a text file (e.g. 'something.txt') using an AJAX call rather than just an anchor tag in HTML. Here is the HTML code: <body> <a href="#" id="exportViewRule">Export</a> </body&g ...

Load charts.js synchronously into a div using XMLHttpRequest

At the moment, there is a menu displayed on the left side of the page. When you click on the navigation links, the page content loads using the code snippet below: if (this.id == "view-charts") { $("#rightContainer").load("view-charts.php"); $(thi ...

Customize Cell Styling with Bootstrap Full Calendar CSS

I am attempting to implement a Bootstrap calendar feature where cells are colored green if the timestamp is greater than today's date. This can be achieved by: $checkTime > $today cell.css = green background I came across this code snippet on St ...

issues with the handler not functioning properly in html and javascript

<form method="post" action="."> <label class="input-label">Enter Your First Name</label><input field="first_name" class="input-edit" maxlength="30" type="text" value="{{ user.first_name }}" /> <label class="i ...

Tips for adding your artistic touch to photos

I'm currently facing a challenge in creating a chart that overlaps an image. The bars and text on the chart are displaying perfectly when I remove the background image. However, I'm struggling to get the bars and text to appear on top of the imag ...

JavaScript Age Calculator - Counting Days

Hey there! I've got an interesting problem. I currently have three text boxes on my webpage, and what I want to achieve is having a fourth text box generated when the user clicks a button. The content of this new text box should be filled with the dat ...

How can I correctly connect a JavaScript library that has been installed via npm?

After using npm to install a JS library, such as: npm install chartjs The necessary JS file is typically located at ./node_modules/chartjs/chart.js. If you prefer the file to be in a different location, like ./public/js/chart.js, you could manually m ...

Using the md-date-picker along with the md-menu component

Whenever I try to click on the md-date-picker inside md-menu, it unexpectedly closes. You can view the issue on this CodePen link. This seems to be a bug related to ng-material as discussed in this GitHub issue. Any suggestions for a workaround? Here is t ...

Adjusting canvas context position after resizing

I've been experimenting with using a canvas as a texture in three.js. Since three.js requires textures to have dimensions that are powers of two, I initially set the canvas width and height to [512, 512]. However, I want the final canvas to have non-p ...

Learn how to insert a <TableRow> in a for loop using Object.keys

<TableBody> {(() => { var result = []; let key = Object.keys(genericResultList)[1]; var list = genericResultList[key]; for (var i = 0; i < list.length; i++) { ***\<!-- Add in the \<T ...

Possible solutions for AngularJS using ng- tags

I absolutely love incorporating AngularJs into my Multiple Pages Laravel Application. However, using the Laravel Blade Template Engine has made me reconsider adding Angular Tags to clutter my blade templates. For instance <div ng-controller="TodoCont ...

Unable to render properly after saving to Firebase

Currently, I am working on developing an express app that creates a Google map using geo coordinates extracted from photos. My goal is to utilize Firebase for storing data related to the images. While my code is functioning properly, I encountered an issue ...

Step-by-step guide on replicating a website along with its CSS styles and scripts

I've been exploring the idea of cloning a webpage, such as Instagram's login page, along with its CSS elements and JavaScript, to use locally. Basically, I want to duplicate the login page and host it on my test server in a way that allows it to ...

Converting ed25519 private key into OpenSSH Format using JavaScript

After generating an ed25519 key pair using the javascript crypto library, I am now faced with the challenge of saving the private key in openssh format. Despite attempting to use the sshpk library for this task, I encountered an issue where the exported k ...

Firefox is unable to render the jQuery file from ajax.googleapis.com

I have Mozilla Firefox version 20.0.1 installed, and I am using the following code on my website: <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!--<script s ...

VueJS 3 is in the process of loading dynamic assets

I am facing an issue with loading and displaying images dynamically from the assets folder in my Vue.js project. The code I have written does not seem to work as expected: <img :src="getSource(data.thumbnail)" :alt="data.name"/> ...

Creating routes in JavaScript to split an object like a tree: a comprehensive guide

When I receive a set of filters as a composed object in my express server, I realized that to create the query I need to split each object route into a separate array of keys. For example: $and: { age: [21, 22], name: { $like: "Alice& ...

Simulated web server for testing with Jest

Can I ask a unique question? I have a tool for extracting data from webpages directly, not through APIs. I want to create end-to-end tests for this tool using the Jest library, but I need to ensure the web pages I'm referencing remain consistent. It&a ...