简体   繁体   English

kendo UI网格数据源asp webforms

[英]kendo UI grid datasource asp webforms

So I followed the example that Kendo Provides to use an external Data Source , for some reason when you put a URL of Default.aspx/GetEvents (Where GetEvents is a webmethod in Default.aspx) it returns the entire HTML of Default.aspx instead of just calling the webmethod in a normal AJAX call. 所以我按照Kendo提供的示例使用外部数据源,出于某种原因,当你输入Default.aspx / GetEvents的URL(其中GetEvents是Default.aspx中的web方法)时,它返回Default.aspx的整个HTML而不是只是在正常的AJAX调用中调用webmethod。

So I found a way around that and I use the local data source method , which calls a javascript function - this javascript function does its own ajax call to my webmethod in default.aspx and gets a successfull response 所以我找到了解决方法,我使用本地数据源方法,它调用javascript函数 - 这个javascript函数在default.aspx中对我的webmethod进行自己的ajax调用并得到一个成功的响应

so here is my code 所以这是我的代码

 $(document).ready(function () {
                $("#grid").kendoGrid({
                    dataSource: {
                        data: createRandomData(),
                        schema: {
                            data: "d"
                        },
                        pageSize: 10
                    },
                    height: 250,
                    scrollable: true,
                    sortable: true,
                    filterable: true,
                    pageable: {
                        input: true,
                        numeric: false
                    },
                    columns: [
                        {
                            field: "Title",
                            title: "Title",
                            width: 100
                        },
                        {
                            field: "StartDate",
                            title: "StartDate",
                            width: 100
                        },
                        {
                            field: "Keywords",
                            width: 100
                        }
                    ]
                });
            });

Here is the begining of what createRandomData() is returning - it's valid json - I just don't want to paste it all and make this question un-readable 这是createRandomData()返回的开始 - 它是有效的json - 我只是不想粘贴它并使这个问题不可读

"d" : [
{
    "Title": "Chicago BlackHawks vs. Detroit Redwings",
    "StartDate": "9/7/2012 12:00:00 AM",
    "Keywords": "-- Select --"
},
{
    "Title": "",
    "StartDate": "1/1/1900 12:00:00 AM",
    "Keywords": "-- Select --"
}, .......

I see no reason why this would not be working , right now the grid just says "loading..." and stays like that for ever , no console errors 我认为没有理由不这样做,现在网格只是说“加载......”并且永远保持这样,没有控制台错误

                    function createRandomData() {
                    $.ajax({
                        type: "POST",
                        url: "MyEvents.aspx/GetEvents",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {                                
                            var rs = msg;
                            return rs;
                        }
                    });
                    return false;
                }

The likely problem is that KendoUI expects a simple javascript call (without AJAX) when using the data element. 可能的问题是KendoUI在使用data元素时需要一个简单的javascript调用(没有AJAX)。 When you call the JS method it returns right away, but AJAX call takes a little bit longer to finish, but Kendo grid never gets notified when the call is done. 当你调用JS方法时,它立即返回,但是AJAX调用需要更长的时间来完成,但是当调用完成时,Kendo网格永远不会得到通知。

What you could try instead is using the transport.read object on the dataSource here . 你可以尝试,而不是使用的是transport.read对象的数据源在这里 This way the grid should work fine with the AJAX call. 这样,网格应该可以与AJAX调用一起正常工作。

EDIT: Have you tried something like this: 编辑:你尝试过这样的事情:

dataSource: {
    transport: {
        read: function(options) {
            $.ajax({
                type: "POST",
                url: "MyEvents.aspx/GetEvents",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {                                
                    options.success(msg.d);
                }
            });
        }
     }
}

Perhaps change your schema defintion: 也许改变您的架构定义:

from this 由此

schema: {
 data: "d"
}

to this 对此

schema: {
 model: {
  fields: {
    Title: { type: "string" },
    StartDate: { type: "string" },
    Keywords: { type: "string" }
   }
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM