【问题标题】:Kendo Grid. How to display dataTextField in Grid's cell instead of dataValueField?剑道网格。如何在 Grid 的单元格中显示 dataTextField 而不是 dataValueField?
【发布时间】:2013-01-31 16:49:17
【问题描述】:

我想为我的 ForigenKey 列显示文本而不是数值。有很多通过比较 ID 来检索 TextMember 的示例,但在我的情况下它们不起作用。我刚开始使用剑道ui,所以不太了解它

代码如下:

$(document).ready(function () {

 dataSource1 = new kendo.data.DataSource({

        transport: {
              read:  {
               url: "Data/AttendanceCode/GridSelect.php",
                dataType: "json",

                            },

                update: {
                   url: "Data/AttendanceCode/GridUpdate.php",
        dataType: "json",
                        type:"GET"
            },

                  destroy: {
                     url: "Data/AttendanceCode/GridDelete.php",
                      dataType: "json",
          type:"POST"
                            },

                    create: {
                      url: "Data/AttendanceCode/GridInsert.php",
                        dataType: "json",
              type:"POST"
                            },

                        },

                  schema: {
         data: "data",

                       model: {
                          id: "AttendenceID",

                           fields: {
                              AttendenceID : { editable: false, nullable: true },
                              TeacherID: { field: "TeacherID", defaultValue: "EIIT0002" },
                                }
                            }
                        },


                    });



$("#grid").kendoGrid({
           dataSource: dataSource1,

    pageSize: 10,
            pageable: {
                refresh: true,
                pageSizes: true
                    },
                    editable:{ mode : "popup" },
                    height: 400,
        filterable: true,
                    columnMenu: true,
        sortable: true, 
                    reorderable: true,
                    resizable: true,
                    toolbar: ["create"],

                    columns: [
                       { field:"AttendenceID", title: "Attendence ID", width:"130px" },

                       { field: "TeacherID", title:"Teacher", width: "100px" , editor: TeacherDropDownEditor, template: "#=getTeacherName(TeacherID)#" },

                   { command: ["edit", "destroy"], title: "Action", width: "210px" }],

                });


            });

教师下拉数据源

teacher = new kendo.data.DataSource({

       transport: {
         read: {
    url : "Data/Teacher.php",
    dataType: "json" }
               },

    schema: {
    data : "Teacher"
         }

    }); 

//教师编辑器

 function TeacherDropDownEditor(container, options) {
   $('<input data-bind="value:' + options.field + '"/>')
.appendTo(container)
     .kendoDropDownList({         
     dataTextField: "TeacherName",
dataValueField: "Service_NO",
 dataSource: teacher
     });
}   

我发现并尝试获取教师姓名的不同方法

1 -

  function getTeacherName(value) {

          var text = "";
     $.each(teacher, function () {
           if (this.Service_NO == value) {
            text = this.Name;
             return false;
           }
        });
     return text;
                      }

2 -

function getTeacherName(teacherID) {

 for (var idx = 0, length = teacher.length; idx < length; idx++) 
   {
    if (teacher[idx].Service_NO === teacherID) 
       {t = teacher[idx].Name;} 
    }                   
return t; 
    }

3 -

function getTeacherName(teacherID) {
      $.each(teacher, function(key, val) {
        if(val.Service_NO == tID){
           t = val.Name;
            }
             });
           return t;
            } 

dataSource(教师)似乎没有任何价值。 PHP 代码运行良好。 如果您知道我的代码有什么问题,请提供帮助。

谢谢!!

【问题讨论】:

  • 代码正在运行。谢谢 OnaBai ... :-)

标签: php kendo-ui kendo-grid


【解决方案1】:

你是对的,teacherDataSource 没有任何数据,因为你正在定义如何获取数据(这就是你对 DataSource 所做的)但你没有阅读它。

添加:

teacher.read();

用于手动强制读取数据。

注意:当您拥有 Grid、ListView 时,会发生这种情况神奇地,因为这些小部件会为您执行此操作,但这次是为了显示您的grid 你需要提前阅读它,因为它是从 JavaScript 函数调用的(KendoUI 网格代码不知道你在函数 getTeacherName 中拥有什么,除了名称)。

【讨论】:

    【解决方案2】:

    你应该配置你的字段:

    { field: "nu_status", title: 'Status', values: [ { text: "Active", value: 1 }, { text: "Inactive", value: 0 }]},
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多