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

retrieving new data set after an event from grid

5 Answers 546 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Entilzha
Top achievements
Rank 2
Entilzha asked on 20 Sep 2013, 03:46 PM
Please don't think I am a jaded customer because I love how using Kendo UI has made me look much better than I am by using your awesome controls.  However, I am using the new scheduler and I am a little frustrated with the (beta) documentation.  So I am finding myself relying on this forum.  Please help.

I need to repopulate the scheduler when a new user has been selected in a companion grid on the page.  I get the selection event with no problem.  Now I just need to know the best way to tell the scheduler to retrieve fresh data from the server based upon the value in the selection event.  After reading through much of the documentation and many of these threads I have come to the conclusion I need to set the dataSource to "serverFiltering: true" and then simply set a new filter.  That didn't call my "Get" function so I tried to force a read call directly.  Still nothing.  Am I approaching this correctly?  What is the best way to handle this?
function onSelectProvider(arg) {
 
     $("#scheduler").filter = { field: "Idd", operator: "eq", value: arg.Text };
     $("#scheduler").dataSource.read();
 }

5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 23 Sep 2013, 08:20 AM
Hello Entilza,

If I understood your scenario correctly, you need to sent an additional parameter to the server when scheduler is databound in order to filter the data. This can be achieved via the DataSource's transport read settings.You will need to rebind the Scheduler DataSource and pass the appropriate field from the currently selected record in the Grid widget. How to configure this is demonstrated in this test page. Please note that in the sample, data will not be filtered as the remote service does not support this operation, however, the data send with the request will be correct.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Entilzha
Top achievements
Rank 2
answered on 23 Sep 2013, 04:01 PM
That is a great answer and I appreciate the code sample.  Unfortunately you left me with understanding the Scheduler less, not more.  Here are two questions:

1.  Can you show me how to do that with MVC?

2.  Because of your answer I am now confused about the role the schema and parameterMap play.  I thought the way to pass back data was to define your model in the parameterMap and then fill it somehow.  What is the difference between the three then? (data, schema, parameterMap)
0
Entilzha
Top achievements
Rank 2
answered on 23 Sep 2013, 04:51 PM
I have a 3rd question (please still answer 1 & 2 above).  Where is the data to be found on the server side?  I did what you suggested and put a break in my server.  When execution stopped at the breakpoint I looked everywhere and could not find the value I had thought was passed back.  Here is my code:

in the .cshtml file:
    var selectedProviderId = -1;
    function onSelectProvider(arg) {
 
        selectedProviderId = arg.ProviderId;// $("#providers-grid").select().data("id");
        $("#scheduler").dataSource.read();
    }
 
        dataSource: {
            autoSync: true,
            serverFiltering: true,
            transport: {
                read: {
                    url: "@Url.Action("Read", "Scheduler")",
                    dataType: "json",
                    data: { providerId: selectedProviderId }
                },
                create: {
                    type: "POST",
                    url: "@Url.Action("Create", "Scheduler")",
                    dataType: "json",
                    data: { providerId: selectedProviderId }
                },
...
}
 
in the controller
public virtual JsonResult Read([DataSourceRequest] DataSourceRequest request) // , int providerId)
{
    var sessions = SessionRepository.Instance.GetAllByProviderId(??); where is the value coming from?
    ...
    return Json(appointments.ToDataSourceResult(request));
}
 
public virtual JsonResult Create([DataSourceRequest] DataSourceRequest request, TaskViewModel task) // , int providerId)
{
    if (ModelState.IsValid)
    {
        //sessionService.Insert(task, ModelState);
        }
 
        return Json(new[] { task }.ToDataSourceResult(request, ModelState));
    }
0
Accepted
Rosen
Telerik team
answered on 24 Sep 2013, 08:09 AM
Hello Entilza,

- You can find attached the same as previous sample but in a ASP.NET MVC application.

In case you are using the Scheduler for ASP.NET MVC you should use the DataSource Read Data option to pass the additional parameters:

@(Html.Kendo().Scheduler<KendoUIMvcApplication2.Models.TaskViewModel>()
    .Name("scheduler")   
    //..
    .DataSource(d => d
        .Read(read => read.Action("Read", "Home").Data("additionalData"))
        //..
    )
)
 
<script>
    function additionalData(e) {
        //get the value of the selected record in the grid
        var grid = $("#grid").getKendoGrid();
        var row = grid.select();
        if (row.length) {
            return {
                user: grid.dataItem(row).get("value")
            }
        }       
    }
</script>

public virtual JsonResult Read([DataSourceRequest] DataSourceRequest request, int? user)
{
    var data = taskService.GetAll();
 
    if (user.HasValue)
    {
        data = data.Where(t => t.OwnerID == user);
    }
 
    return Json(data.ToDataSourceResult(request));
}


- As stated in the documentation:
  •  The transport.[operation].data is place to assign additional parameters which to be sent to the remote service. It is similar to jQuery.ajax's data option.
  •  The parameterMap is a function which converts the request parameters (both the DataSource sort, filter, etc. operation descriptors and model changes, as well as custom ones assign via the transport data) to a format suitable for the remote service.
  •  The schema describes the remote service response

- The additional parameter should be mapped (if configured correctly) to a parameter with the same name in the appropriate action. 

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Entilzha
Top achievements
Rank 2
answered on 24 Sep 2013, 12:46 PM
You guys are awesome and give the best answers!  We very much appreciate it.  Thanks for making everything so clear and obvious!
Tags
Scheduler
Asked by
Entilzha
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Entilzha
Top achievements
Rank 2
Share this question
or