.NET Kendo Scheduler: dynamically change datasourc

2019-09-18 19:39发布

Now i'm using a datasource like this: (with the parameters to filter hard coded)

   $(function () {
        $("#scheduler").kendoScheduler({
            date: new Date(Date.now()),
            startTime: new Date(2013, 5, 13, 9, 0, 0, 0),
            height: 800,
            timezone: "Etc/UTC",
            group: {
                resources: ["Rooms"]
            },
            resources: [
                {
                    name:"Rooms",
                    title: "Room",
                    field: "RoomID",
                    dataSource: {
                        transport:
                            {
                                read: { url: "@Html.Raw(Url.Action("Filter_Rooms", "Room", new{
                                    pPar1= true,
                                    pPar2 = false,
                                    pPar3 = true,
                                         }))", dataType: "json" }
                            }
                    }
                }

As you can see these paramaters are still hard coded and I want to change them whenever the user wants using checkboxes:

<div class="checkbox">
    <label>
    <input id="chkPar1" type="checkbox"> Parameter 1
    </label>
</div>
<div class="checkbox">
    <label>
    <input id="chkPar2" type="checkbox"> Parameter 2
    </label>
</div>   
    <a href="#" id="btnFilter" class="btn btn-outline btn-primary btn-lg btn-block">Filter</a>

I thought while using javascript to check if button is clicked and then store checkbox paramaters in global variables and use these in the transport read of the scheduler but it seems you can't use document.getelementbyId here.

Here they suggested Kendo UI Dynamically Change Datasource String (XML) but that doesn't seem to work for me neither..

var dynamicUrl = "Html.Raw(Url.Action('Filter_Rooms', 'Room', new{pFilter = true, pCapacity = 25,pBeamer = true,pTelevision = false}))', dataType: 'json'"
var scheduler = $("#scheduler").data("kendoScheduler");
scheduler.dataSource.transport.options.read.url = dynamicUrl;

So How can I dynamically change these paramaters or update the entire transport read url?

Regards

2条回答
劫难
2楼-- · 2019-09-18 20:21

Not sure if it's exactly what you're after, but a good frame of reference might be this example project. It very simply shows how to load new content when you change the view. You may be able to adapt it.

查看更多
贪生不怕死
3楼-- · 2019-09-18 20:35

Try this:

var pFilter = (document.getElementById("someID").value);
var pCapacity = document.getElementById("someID").value;
var pBeamer = document.getElementById("someID").value;
var pTelevision = document.getElementById("someID").value;

var dynamicUrl = "Html.Raw(Url.Action('Filter_Rooms', 'Room', new{pFilter = " + pFilter +  ", pCapacity = " + pCapacity + ",pBeamer = " + pBeamer + ",pTelevision = " + pTelevision + "}))', dataType: 'json'"

There could be some type of string format that you could use like in C# but I'm not sure. Hope this works!

查看更多
登录 后发表回答