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

scheduler binding/ajax issues

6 Answers 242 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 23 Dec 2013, 09:47 PM
I'm attempting to use a custom editor template in a kendo scheduler but have 2 issues.  

1.  I have a mutliselect in the editor template, and am unable to get the selected options to bind and be posted to the server.
2.  My ajax requests are wonky.  
  2a.  What I'm seeing is when i click save it fires the datasource.create method multiple times (sometimes twice sometimes 3 times) and posts the same data to the server.
  2b.  When i attempt to delete an event the datasource.create endpoint is hit and not the datasource.destroy method.


I've attached a solution with an example.  I've neven used these custom editor templates before so i think its likely im not binding it properly.

Thanks,
Chris
  

6 Answers, 1 is accepted

Sort by
0
chris
Top achievements
Rank 1
answered on 23 Dec 2013, 10:06 PM
deleting this post, i was able to upload an example.
0
Dimo
Telerik team
answered on 25 Dec 2013, 03:13 PM
Hello Chris,

When sending projects to support staff, it is recommended to make sure they are configured correctly and runnable without the need to makes fixes and adjustments, for example (in this case) adding missing script files, removing duplicate registrations of Kendo UI scripts and replacing mismatched Kendo UI assembly reference. Thank you for understanding.

The Create action will be called only once, and the Destroy action will be called as expected if you define the Model and its ID in the DataSource configuration, as demonstrated at

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/scheduler/ajax-editing

and in our demos, in which the Scheduler uses Ajax binding.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
chris
Top achievements
Rank 1
answered on 26 Dec 2013, 05:47 PM
Thanks Dimo,

I didn't realizing defining my model was required in the helper when i specified the type in the helpers definition.  I will define the model.  This doesn't address my other issue though which is how to i incorporate a multiselect in the editor template and have the selected values sent properly to the server?  If you notice my class OutageEvent has a list<string> called LocationIds.  I have a multilselect rendering in the editor template but that attribute doesn't get bound properly so that my action method sees it... that property is always null.

Please advis,

Chris
0
Accepted
chris
Top achievements
Rank 1
answered on 26 Dec 2013, 08:01 PM
Ok so it seems that I needed to format the list data using a javascript function before posting it to the server.

<script type="text/javascript">
    var getUpdateData = function (data) {
        MultiSelectHelpers.serialize(data);
    };
 
    var MultiSelectHelpers = {
        serialize: function(data) {
            for (var property in data) {
                if ($.isArray(data[property])) {
                    this.serializeArray(property, data[property], data);
                }
            }
        },
        serializeArray: function(prefix, array, result) {
            for (var i = 0; i < array.length; i++) {
                if ($.isPlainObject(array[i])) {
                    for (var property in array[i]) {
                        result[prefix + "[" + i + "]." + property] = array[i][property];
                    }
                } else {
                    result[prefix + "[" + i + "]"] = array[i];
                }
            }
        }
    };
</script>
change my helper definition like this:
.Timezone("Etc/UTC")   
      .DataSource(
          d =>
              {
                  d.Model(m=>
                  {
                      m.Id(i=>i.Id);
                  });
                  d.Read(r => r.Action("ReadEvents", "Outage", new { Area = "GatewayManagement" }).Type(HttpVerbs.Post));
                  d.Update(u => u.Action("UpdateEvent", "Outage", new { Area = "GatewayManagement" }).Data("getUpdateData").Type(HttpVerbs.Post));
                  d.Destroy(u => u.Action("DestroyEvent", "Outage", new { Area = "GatewayManagement" }).Data("getUpdateData").Type(HttpVerbs.Post));
                  d.Create(u => u.Action("CreateEvent", "Outage", new { Area = "GatewayManagement" }).Data("getUpdateData").Type(HttpVerbs.Post));
              }
Then the server binds the List<string> properly.  Not really sure why this is needed.  But came across this:


http://stackoverflow.com/questions/16142746/kendo-ui-multiselect-post-binded-values-to-the-controller
0
ShareDocs
Top achievements
Rank 1
answered on 16 Jan 2014, 05:59 PM
chris, can you upload a working example?
I'm trying to create a working multiselect inside a scheduler template but can't seem to grip the right way of doing this.

Will appreciate any help with this as I am pretty stuck with trying to pass the data from the scheduler to the template...

I followed your first post but I always get an empty model with the message:

 System.ArgumentNullException: Value cannot be null.
Parameter name: source


can you please assist?

Telerik Team: forgive me for duplicating my question but this post seems to be very related to my problem
0
ShareDocs
Top achievements
Rank 1
answered on 19 Jan 2014, 05:18 AM
Eventually I did as telerik instructed on code library.
Worked like a charm
Tags
Scheduler
Asked by
chris
Top achievements
Rank 1
Answers by
chris
Top achievements
Rank 1
Dimo
Telerik team
ShareDocs
Top achievements
Rank 1
Share this question
or