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

Pass additional parameters to Read ajax datasource

3 Answers 933 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Logan
Top achievements
Rank 1
Veteran
Logan asked on 27 Feb 2018, 02:28 PM

I would like to pass additional parameters from the page to the scheduler read via javascript.  I have done this in the past with the kendo grid and this thread implies that the scheduler should work the same way https://www.telerik.com/forums/pass-additional-parameters-to-read-ajax-datasource-method---mvc but it isn't working for me.

 

I get the following error:

Compiler Error Message: CS1061: 'SchedulerAjaxDataSourceBuilder<CalendarItemGridItem>' does not contain a definition for 'Data' and no extension method 'Data' accepting a first argument of type 'SchedulerAjaxDataSourceBuilder<CalendarItemGridItem>' could be found (are you missing a using directive or an assembly reference?)

Source Error:
Line 42: m.RecurrenceId(f => f.RecurrenceId);

Line 43: })

Line 44: .Read("Schedule_Read", "Calendar").Data("getSchedulerData")

Line 45: .Create("Schedule_Create", "Calendar")

Line 46: .Destroy("Schedule_Destroy", "Calendar")

3 Answers, 1 is accepted

Sort by
0
Logan
Top achievements
Rank 1
Veteran
answered on 27 Feb 2018, 08:27 PM

There might be a way to do this through the kendo system, but i ended up just adding an ajax prefilter.  This adds it to every ajax post that happens on the page.

$.ajaxPrefilter(
        function (options, localOptions, jqXHR) {
            if (options.type != "GET") {
                var token = getAntiForgeryPair();
                if (token != null && token.value != null) {
                    if (options.data == null || options.data.indexOf("X-Requested-With") == -1) {
                        var xr = "X-Requested-With=XMLHttpRequest";
                        options.data = (options.data == null || options.data == "") ? xr : xr + "&" + options.data;
                    }
 
                    options.data = options.data + "&" + $.param($('#params').serializeObjectForPost());
                }
            }
        });

 

 

 

0
Logan
Top achievements
Rank 1
Veteran
answered on 27 Feb 2018, 08:30 PM
I don't appear to be able to edit my post, but i should clarify that the code above also adds the antiforgery token.
0
Neli
Telerik team
answered on 01 Mar 2018, 12:01 PM
Hi Logan,

Attached you will find a sample project. In the project the transport.read.data option is used for sending additional parameters to the controller, as it is discussed in the Forum thread you found. you can see the behavior on my end on the linked screencast.
Could you please try to modify the project in order to replicate the behavior the way it is at your end? This will helps us to inspect the issue locally and advise you further. 

Regards,
Neli
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
Logan
Top achievements
Rank 1
Veteran
Answers by
Logan
Top achievements
Rank 1
Veteran
Neli
Telerik team
Share this question
or