kendo grid外部列选择的文本被客户端模板覆盖

问题描述 投票:1回答:1

我在MVC项目上有一个kendo网格,带有一个foreignKey列,在同一列上有一个客户端模板,用于将数据发送到控制器(隐藏),因为我在kendo网格上方有一个标题信息,我想发送给控制器。一切正常。但是当我选择网格中的下拉列表时,它会显示值而不是文本。

columns.ForeignKey(c => c.studentId,(System.Collections.IEnumerable)ViewData [“Students”],“Id”,“name”)。标题(“id - name”)。宽度(70)

.ClientTemplate(“#= studentId#”+“<'input type ='hidden'name ='MyModel [#= index(data)#]。StudentId'value ='#= StudentId#'/>”);

以上是我目前的确切代码。

如何向用户显示所选文本(本例中为名称)而不是kendo网格上的值(本例中为Id)。

谢谢

kendo-ui grid selected
1个回答
2
投票

刚刚遇到同样的问题,发现这个问题在telerik site

基本上创建一个函数,从网格中的外键下拉查找文本。

 columns.ForeignKey(c => c.G_ID, plus, "Value", "Text").Title("Plu").Lockable(true).ClientFooterTemplate("Total").ClientTemplate("#= getTextByValue(data)#" +
        "<input type='hidden' name='Schedules[#= index(data)#].G_ID' value='#= G_ID #' />"); //.Hidden();

和javascript:

var collection;

功能:

function getTextByValue(data) {
    console.log(data);
    var dGrid = $("#the-dtl-grid").data("kendoGrid");
    //change the index of the column with your index
    valuesCollection = dGrid.options.columns[1].values;

    //if the collection is empty - get it from the grid
    if (!collection) {
        collection = {};
        //Set the correct FKColumn index
        for (var value in valuesCollection) {
            collection[valuesCollection[value].value] = valuesCollection[value].text;
        }
    }
    return collection[data.G_ID];
}
© www.soinside.com 2019 - 2024. All rights reserved.