[英]assigning Datasource of kendo grid in Javascript part. (Asp.net MVC-Razor Engine)
I want to assign the datasource of the kendo grid in Javascript part of the View, as i want to display it in response to selecting another object from another kendogrid on the same page, so i want to pass the value of this object to the controller back and then view the grid. 我想在视图的Javascript部分中分配kendo网格的数据源,因为我想在同一页面上从另一个kendogrid中选择另一个对象时显示它,因此我想将此对象的值传递给控制器返回,然后查看网格。
I found the best way is to assign the datasource in the javascript function related to the selection part, if there is better ideas, please suggest it. 我发现最好的方法是在与选择部分相关的javascript函数中分配数据源,如果有更好的主意,请提出建议。
Kendo grid : 剑道网格
@(Html.Kendo().Grid<dynamic>()
.Name("StatusGrid")
//.HtmlAttributes(new { style="width:50%;" })
.Columns(columns =>
{
foreach (System.Data.DataColumn c in Model.GridStatus.Columns)
{
columns.Bound(c.ColumnName).EditorTemplateName("String");
}
})
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model =>
{
foreach (System.Data.DataColumn column in Model.GridStatus.Columns)
{
model.Field(column.ColumnName, column.DataType);
model.Id("Id");
}
})
//.Read(read =>
// read.Action("ActivityGridDisplay", "Configuration")
//)
))
So how to write this part in the javascript:( assigning the read and the model) ? 那么如何在javascript :(分配读取和模型)中编写此部分呢?
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model =>
{
foreach (System.Data.DataColumn column in Model.GridStatus.Columns)
{
model.Field(column.ColumnName, column.DataType);
model.Id("Id");
}
})
.Read(read =>
read.Action("ActivityGridDisplay", "Configuration")
)
))
It can be done in an easier way, just to assign or bind the read part using ajax, even you can pass some variables with that read part using javascript which i find easier than kendo: 可以用一种更简单的方式来完成它,只需使用ajax分配或绑定读取的部分,即使您可以使用javascript传递一些变量来读取该部分,我发现它比kendo还容易:
function onChange(e) {
var grid = $("#grid").data("kendoGrid");
var dataRows = grid.items();
var rowIndex = dataRows.index(grid.select());
var selectedname = grid.dataItems()[rowIndex];
document.getElementById("ActivityGrid").style.bottom = "0px";
$.ajax({
url: '/Configuration/ActivityGridDisplay',
contentType: 'application/html charset=utf-8',
type: 'GET',
dataType: 'html',
data: { 'nodeName': selectedname.Name, 'nodeType': selectedname.Type, 'nodeID': selectedname.NodeId },
success: function (data) {
$('#body').html(data);
}
})
}
and the edited part of the question 和问题的编辑部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.