Pass additional parameters to Read ajax datasource

4 posts, 0 answers
  1. Logan
    Logan avatar
    61 posts
    Member since:
    Apr 2013

    Posted 27 Feb 2018 Link to this post

    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")

  2. Logan
    Logan avatar
    61 posts
    Member since:
    Apr 2013

    Posted 27 Feb 2018 Link to this post

    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());
                    }
                }
            });

     

     

     

  3. Logan
    Logan avatar
    61 posts
    Member since:
    Apr 2013

    Posted 27 Feb 2018 in reply to Logan Link to this post

    I don't appear to be able to edit my post, but i should clarify that the code above also adds the antiforgery token.
  4. Neli
    Admin
    Neli avatar
    292 posts

    Posted 01 Mar 2018 Link to this post

    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.
Back to Top