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

create (batch-mode) is not triggered

2 Answers 140 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Bastian
Top achievements
Rank 1
Bastian asked on 20 Mar 2017, 03:16 PM

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 Answers, 1 is accepted

Sort by
0
Bastian
Top achievements
Rank 1
answered on 20 Mar 2017, 03:18 PM
<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>
0
Ivan Danchev
Telerik team
answered on 22 Mar 2017, 01:14 PM
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.
Tags
MultiSelect
Asked by
Bastian
Top achievements
Rank 1
Answers by
Bastian
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or