简体   繁体   English

使用Kendo JS填充网格

[英]Populating a grid using kendo js

I am working on a web app which needs to populate a grid with some data. 我正在开发一个Web应用程序,该应用程序需要用一些数据填充网格。 I have a button wired with a onClick method which opens a new modal window for the grid to be displayed. 我有一个与onClick方法连接的按钮,它将为要显示的网格打开一个新的模式窗口。 I am using a jquery post call to the controller. 我正在使用jquery调用控制器。 However, I am unable to get the json data and assign it to my variable. 但是,我无法获取json数据并将其分配给我的变量。

My code is as follows: 我的代码如下:

var grid_ds;
$.post('${ctx}/class/student/details?studentId=${student.studentId}', function(data){




}, 'json');

$('#student_grid').kendoGrid({
dataSource: grid_ds,
columns: [
{field: "studentName", title: "Student Name"},
{field: "studentClass", title: "Class"}
],
dataBound: function () {
     emptyGrid($('#student_grid'));
}
}).data('kendoGrid');

My controller sends json back. 我的控制器将json发送回去。 I can see the data coming. 我可以看到数据即将到来。 How should I assign the json data to grid_ds and student_grid and make the values populate in the grid. 我应该如何将json数据分配给grid_ds和student_grid并使值填充在网格中。

You could try using a kendo.data.DataSource with a custom transport function like so: 您可以尝试使用带有自定义transport功能的kendo.data.DataSource ,如下所示:

$('#student_grid').kendoGrid({
    dataSource: dataSource = new kendo.data.DataSource({
        transport: {
            read: function (e) {
                $.post('${ctx}/class/student/details?studentId=${student.studentId}', 'json')
                    .done(function (data) {
                        e.success(data);
                    });
            }
        }
    }),
    columns: [
        {
            field: "studentName",
            title: "Student Name"
        },
        {
            field: "studentClass",
            title: "Class"
        }
    ]});

I think the problem may be with how you're fetching the data. 我认为问题可能出在您如何获取数据上。 Since $.post is an ajax call operating out of band, grid_ds is most likely undefined when being passed to the .kendoGrid() function. 由于$.post是一个带外操作的ajax调用, grid_ds当传递给.kendoGrid()函数时, grid_ds很可能是未定义的。

I wasn't able to locate the dataBound configuration property that you specify in your question in the kendo.ui.Grid . 我是不是能够找到dataBound ,你在你的问题中指定配置属性kendo.ui.Grid Do you happen to know where this configuration setting came from? 您是否偶然知道此配置设置来自何处?

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

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