This is a migrated thread and some comments may be shown as answers.

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

1 Answer 272 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Eyal
Top achievements
Rank 1
Eyal asked on 16 Jun 2015, 06:05 AM

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 ! 

 

 


1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Jun 2015, 08:00 AM
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!
 
Tags
Data Source
Asked by
Eyal
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or