我正在使用带有报告数据的kendu网格,网格在正常情况下工作正常但我的问题是网格的列和架构属性不会是静态的,这就是为什么我想动态添加它,但我无法设置它
这是我的代码:
$(document).ready(function () {
var obj = {
fields: {
}
};
var Column1;
$("#grid").kendoGrid({
dataSource: {
type: "data",
transport: {
read: function (options) {
$.ajax({
type: "GET",
url: "http://localhost:3833/Service1.svc/GetJSON1",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var t2 = msg.GetJSON1Result;
var data1 = $.parseJSON(t2.data);
Column1 = t2.columns;
var t11 = Column1;
obj = {
fields: {
}
};
$.each(Column1, function (i, value) {
obj.fields[value.field] = { type: "number" };
}
);
var Schema1 = {
model: obj
}
var gridDetails = $("#grid");
**//Setting schema to grid but it's not effective**
gridDetails.schema = Schema1;
**//Setting schema to grid but it's not effective**
gridDetails.columns = Column1;
options.success(data1);
options.success(Schema1);
options.success(Column1);
}
});
}
},
pageSize: 50,
serverFiltering: false ,
serverSorting: false,
serverPaging: false,
},
height: 550,
reorderable: true,
filterable: true,
sortable: true,
pageable: true,
scrollable: true,
resizable: true,
groupable: true
});
});
请帮帮我。我是kendu的新手
此致 Ajeet Kumar
答案 0 :(得分:0)
要更改网格列,首先需要将其销毁,然后再次初始化。这是一些代码:
var grid = $("#grid").data("kendoGrid");
var options = grid.options;
grid.destroy();
options.columns = [ /* set the columns */ ];
grid.destroy();
$("#grid").empty().kendoGrid(options);