parameterMap - "type" parameter is undefined on nested datasource

2 posts, 0 answers
  1. Martin
    Martin avatar
    3 posts
    Member since:
    Feb 2014

    Posted 17 Mar 2014 Link to this post

    Hi,

    I am using parameterMap function in HierarchicalDataSource. At root level everything works as expected. But when it is called from nested datasource, then "type" parameter is undefined. I need mapping only for "create" request.

    My treeview definition with datasource looks like this:

    $("#tree").kendoTreeView({
            dragAndDrop: true,
            dataSource: {
                transport: {
                    read: {
                        url: '@Url.Action("Read", "TreeView")'
                    },
                    update: {
                        url: '@Url.Action("Update", "TreeView")',
                        dataType: 'json',
                        type: 'POST'
                    },
                    create: {
                        url: '@Url.Action("Create", "TreeView")',
                        type: 'POST',
                        contentType: "application/json; charset=utf-8",
                        dataType: 'json'
                    },
                    parameterMap: function (data, type) {
                        if (type == "create") {
                            return JSON.stringify(data);
                        }
                        return data;
                    }
                },
                schema: {
                    model: {
                        id: "Id",
                        hasChildren: "HasChildren"
                    }
                }
            },
            dataTextField: 'Name',
            drop: onTreeviewDrop,
            drag: onTreeviewDrag
        });

    Thanks for any help!

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 19 Mar 2014 Link to this post

    Hello Martin,

    Thank you for noticing. We will include the type parameter for one of the next internal builds. For now I can suggest to save the type in the requestStart event and then check the saved value in the parameterMap function e.g.
    var requestType;
    $("#tree").kendoTreeView({
        dragAndDrop: true,
        dataSource: {
            transport: {
                read: {
                    url: '@Url.Action("Read", "TreeView")'
                },
                update: {
                    url: '@Url.Action("Update", "TreeView")',
                    dataType: 'json',
                    type: 'POST'
                },
                create: {
                    url: '@Url.Action("Create", "TreeView")',
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json'
                },
                parameterMap: function (data, type) {
                    if (requestType == "create") {
                        return JSON.stringify(data);
                    }
                    return data;
                }
            },
            requestStart: function (e) {
                requestType = e.type;
            },
            schema: {
                model: {
                    id: "Id",
                    hasChildren: "HasChildren"
                }
            }
        },
        dataTextField: 'Name',
        drop: onTreeviewDrop,
        drag: onTreeviewDrag
    });

    Please note that currently the HierarchicalDataSource does not provide any special handling for the create, destroy and update operations for hierarchical data(e.g. calling sync on the treeview dataSource will not automatically synchoronize the children dataSources). 

    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