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

parameterMap - "type" parameter is undefined on nested datasource

1 Answer 161 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 17 Mar 2014, 04:40 PM
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!

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Mar 2014, 12:28 PM
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!
 
Tags
Hierarchical Data Source
Asked by
Martin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or