"stringifyDates": true { kendo.data.DataSource } and posting Date value to Controller (Grid Inline edit mode)

2 posts, 0 answers
  1. Eyal
    Eyal avatar
    4 posts
    Member since:
    Jun 2014

    Posted 16 Jun 2015 Link to this post

    Hello, 

    In some demos & examples I found this : "stringifyDates": true  in the data source configuration, 
    but didn't find anything in the documentation about this. (looks like a secret settings option Telerik uses on their demos  ;-) 

    is somebody has a documentation about this "stringifyDates": true ?

    another thing on same subject,  I try to use the parameterMap , to parse the model sent to the server,

    and stringify the date in the model "SupplyDate": { "type": "date" }, but  its never called! 

    please see example here.

    var ds = new kendo.data.DataSource({
        "type": (function () { if (kendo.data.transports['aspnetmvc-ajax']) { return 'aspnetmvc-ajax'; } else { throw new Error('The kendo.aspnetmvc.min.js script is not included.'); } })(),
        "transport": {
            "read": {
                "url": '/Controller/Products_Get',
                "data": function () {
                    return {
                        "OrderNumber": "0001"
                    };
                },
                "complete": function (jqXHR, textStatus) {
                    if (textStatus == "error") {
                        var msg = "read event completed with error. invalid url or other javascript error";
                        console.log(msg);
                    } else {
                        var result = JSON.parse(jqXHR.responseText);
                        console.log("jqXHR.responseText:\n" + jqXHR.responseText, '#ffffff', '#0011cc');
                    }
                }
            },
            "update": {
                "//type": "POST",
                //"dataType": "json",
                //"contentType": "application/json",
                "url": '/Controller/Product_Upsert',
                "complete": function (jqXHR, textStatus) {
                    Parse_UpsertOrDelete_Complete("update", jqXHR, textStatus);
                }
            },
            "create": {
                //"type": "POST",              
                //"dataType": "json",
                //"contentType": "application/json",
                "url": '/Controller/Product_Upsert',
                "complete": function (jqXHR, textStatus) {
                    Parse_UpsertOrDelete_Complete("create", jqXHR, textStatus);
                }
            },
            "destroy": {
                //"type": "POST",               
                //"dataType": "json",
                //"contentType": "application/json",
                "url": '/Controller/Product_Delete',
                "complete": function (jqXHR, textStatus) {
                    Parse_UpsertOrDelete_Complete("destroy", jqXHR, textStatus);
                }
            },
            "stringifyDates": true,
            "prefix": "",
            "parameterMap": function (data, operation) {
     
                console.log("operation: " + operation + " data: " + JSON.stringify(data));
     
                if (operation === "update" || operation === "create" || operation === "destroy") {
                    return JSON.stringify({ entity: data });                   
                }
                return data;
            }
        },
        "pageSize": 1000,
        "page": 1,
        "total": 0,
        "serverPaging": true,
        "serverSorting": true,
        "serverFiltering": true,
        "serverGrouping": true,
        "serverAggregates": true,
        "filter": [],
        "error": function (jqXHR) {
            console.log("jqXHR.status =" + jqXHR.status);
        },
        "schema": {
            "data": "Data",
            "total": "Total",
            "errors": "Errors",
            "model": {
                "id": "ProductionOrderNumber",
                "fields": {                                       
                    "OrderNumber": { "type": "number" },
                    "SupplyDate": { "type": "date" },                   
                    "CustomerName": { "type": "string" },                   
                    "Units": { "type": "number" }
                }
            }
        }
    });

     

     

    function Parse_UpsertOrDelete_Complete(action, jqXHR, textStatus) {

     // handle complete...

    }

     

     

    Controller

    class ProductEntity {
        public int OrderNumber {get;set;}
        public DateTime SupplyDate {get;set;}                   
        public string CustomerName {get;set;}                 
        public int Units {get;set;}
    }
     
    [AcceptVerbs(HttpVerbs.Post)]
    public async Task<ActionResult> Product_Upsert([DataSourceRequest]DataSourceRequest request,
                       ProductEntity entity)
    {
     
            ProductEntity product =  entity;
     
            // product.SupplyDate  not set correctly when not using
            //  (   "stringifyDates": true  in the DataSource )
     
              
    }


    Thanks ! 

     

     


  2. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 18 Jun 2015 Link to this post

    Hello,

    stringifyDates is an internal option used by scheduler MVC wrapper. It is not documented because it is not intended for public use.

    The parameterMap function will not be called because the type is set to "aspnetmvc-ajax". In this case a specific for the wrappers transport will be used which does not allow a custom parameterMap function. If you need to override it then you should remove the type option. In this case, in order for the dataSource state to be sent as expected by the DataSourceRequestAttribute , you could create a separate "aspnetmvc-ajax" transport and use its parameterMap function to serialize the options for the read request:
    "parameterMap": function (data, operation) {
        if (operation === "update" || operation === "create" || operation === "destroy") {
            return JSON.stringify({ entity: data });                  
        }
        var transport = new kendo.data.transports["aspnetmvc-ajax"]();
        return transport.parameterMap(data, operation);
        return data;
    }


    Regards,
    Daniel
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top