Date format is changing while fetching data using Kendo Grid

前端 未结 1 1721
情深已故
情深已故 2021-01-28 11:25

I am trying to fetch and load data to a kendo grid using some parameters. But when I am using date parameter, format of date is changing hence showing me wrong dates in server s

1条回答
  •  醉话见心
    2021-01-28 12:09

    I too had this problem, i solved it by checking the data format at the time of saving.

    1- find the data while saving

     var dataS = $("#grid").data("kendoGrid").dataSource;
     var updatedData = dataS._data;
    

    2- check the format and then save it, my data parameter is rsrc_dt

        var dateValue = updatedData[i].rsrc_dt;
        var day; var year; var mon;
        if (typeof dateValue === 'string' || dateValue instanceof String) {
        day = dateValue.split('/')[0];  // use when date is not in correct string format
        mon = dateValue.split('/')[1];
        year = dateValue.split('/')[2];
        var dateS = day + '/' + mon + '/' +year;
        serverData[i].rsrc_dt = dateValue;
        }
        else if (dateValue instanceof Date) {
        var date = new Date(updatedData[i].rsrc_dt);
        year = date.getFullYear();
        day = date.getDate();
        day = day < 10 ? '0' + day : day
        mon = date.getMonth();
        mon = mon + 1;
        mon = mon < 10 ? '0' + mon : mon;
        var dateF = day + "/" + mon + "/" + year;
        serverData[i].rsrc_dt = dateF;
        }
    

    3- You may try this also, give format of data in field template like this one

         { field: "rsrc_dt", title: "Session Date", format: "{0:dd/MM/yyyy}", editor: dateTimeEditor, width: 73, attributes: { "class": "azN" }, },
    

    4- Use DateEditor

      function dateTimeEditor(container, options) {
      $('')
                .appendTo(container)
                .kendoDatePicker({ min: btch_strt_dt });
    
    }
    

    0 讨论(0)
提交回复
热议问题