create (batch-mode) is not triggered

3 posts, 0 answers
  1. Bastian
    Bastian avatar
    4 posts
    Member since:
    Feb 2017

    Posted 20 Mar 2017 Link to this post

    Hi,

     

    i have problems with a json-based create method. Read is called and everything is displayed fine. But adding items does not trigger the create url. I tried adding new items wit id=0 or null or completely empty. But it is not working? What do I miss?

    <script id="noDataTemplate" type="text/x-kendo-tmpl"> <div> No data found. Do you want to add new item - '#: instance.input.val() #' ? </div> <br /> <button class="k-button" onclick="addNew('#: instance.element[0].id #', '#: instance.input.val() #')">Add new item</button> </script><script> function addNew(widgetId, value) { var widget = $("#" + widgetId).getKendoMultiSelect(); var dataSource = widget.dataSource; dataSource.add({ name : value }); dataSource.sync(); } </script><script> $(document) .ready( function() { $("#title").kendoDropDownList(); $("#sex").kendoDropDownList(); var dataSource = new kendo.data.DataSource( { batch: true, transport : { read : { url : "http://XXX/tags?objectType=user", dataType : "json" }, create : { url : "http://XXX/tag/createForUser", dataType : "json", type: "POST" }, parameterMap : function(data, type) { if (type !== "read") { // send the created data items as the "models" service parameter encoded in JSON return { models : kendo .stringify(data.models) }; } } }, schema: { model: { id: "id", fields: { name: { type: "string" } } } } }); $("#tags").kendoMultiSelect( { filter : "startswith", dataTextField : "name", dataValueField : "id", dataSource : dataSource, noDataTemplate : $( "#noDataTemplate").html() }); /* $("#tags") .data("kendoMultiSelect") .value( /*[]*/ //[]); }); </script>

  2. Bastian
    Bastian avatar
    4 posts
    Member since:
    Feb 2017

    Posted 20 Mar 2017 in reply to Bastian Link to this post

    <script id="noDataTemplate" type="text/x-kendo-tmpl">
            <div>
                No data found. Do you want to add new item - '#: instance.input.val() #' ?
            </div>
            <br />
            <button class="k-button" onclick="addNew('#: instance.element[0].id #', '#: instance.input.val() #')">Add new item</button>
        </script>
            <script>
                function addNew(widgetId, value) {
                    var widget = $("#" + widgetId).getKendoMultiSelect();
                    var dataSource = widget.dataSource;
                     
                    dataSource.add({
                        name : value
                    });
     
                    dataSource.sync();
     
     
                }
            </script>
            <script>
                $(document)
                        .ready(
                                function() {
                                    $("#title").kendoDropDownList();
                                    $("#sex").kendoDropDownList();
     
                                    var dataSource = new kendo.data.DataSource(
                                            {
                                                batch: true,
                                                transport : {
                                                    read : {
                                                        url : "http://X/tags?objectType=user",
                                                        dataType : "json"
                                                    },
                                                    create : {
                                                        url : "http://X/tag/createForUser",
                                                        dataType : "json",
                                                        type: "POST"
                                                    },
                                                    parameterMap : function(data,
                                                            type) {
                                                        if (type !== "read") {
                                                            // send the created data items as the "models" service parameter encoded in JSON
                                                            return {
                                                                models : kendo
                                                                        .stringify(data.models)
                                                            };
                                                        }
                                                    }
                                                },
                                                   schema: {
                                                        model: {
                                                            id: "id",
                                                            fields: {
                                                                name: { type: "string" }
                                                            }
                                                        }
                                                    }
                                            });
     
                                    $("#tags").kendoMultiSelect(
                                            {
                                                filter : "startswith",
                                                dataTextField : "name",
                                                dataValueField : "id",
                                                dataSource : dataSource,
                                                noDataTemplate : $(
                                                        "#noDataTemplate").html()
                                            });
                         
     
                                });
            </script>
  3. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2053 posts

    Posted 22 Mar 2017 Link to this post

    Hello Bastian,

    Here's a sample dojo, in which adding a new item to the MultiSelect works correctly. Does your action in the controller have the [HttpPost] attribute set?

    Regards,
    Ivan Danchev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top