剑道网格错误-网格.选择不是函数为什么

Error in kendo grid - grid.select is not a function why?

本文关键字:网格 函数 为什么 错误 选择      更新时间:2023-09-26

我有一个kendoDropDown列表作为我的网格单元格。我正在使用剑道网格("编辑器")的编辑器命令调用kendDropDownList。我需要将选定行的选定值传递给kendoDropDownList作为参数,以便服务器仅以过滤列表作为我的kendoDropDownList回复。请看下面的例子

                         var grid =  $("#grid").kendoGrid({
                    dataSource: dataSource,
                    pageable: true,
                    columnMenu:true,
                    filterable:true,
                    height: 550,
                    reorderable: true,
            columnReorder: function(e) {
                        console.log(e.column.field, e.newIndex, e.oldIndex);
                      },
                    toolbar: ["create","excel","save", "cancel" , { template: kendo.template($("#template").html()) } , { template: kendo.template($("#clearFilterTemplate").html()) } , { name: "create", text: "Add New Employee" }],
                    excel: {
                            fileName: "Kendo UI Grid Export.xlsx",
                            proxyURL: "excelExport",
                            filterable: true,
                            allPages: true
                        },                        
                     editable: "inline" , //editable: true,
                     columns: [
                                { field: "fileNo" , title:"File No" , width: 80 },
                                { field: "jobNo" , title:"Job No" , width: 80 },
                                { field: "discipline" , title:"Discipline" , width: 80 },
                                { field: "moduleNo" ,title:"Module", width: 100},
                                { field: "description",title:"Title",editor: descriptionDropDownEditor, width: 150},
                                { field: "documentNo",title:"Document No", width: 150 },
                                { field: "remarks",title:"Remarks" , width: 150 } ,
                                { command: ["edit","destroy"], title: " ", width: "250px" }
                            ]

                });

                function descriptionDropDownEditor(container, options) {
                 // here is the error grid.select is not a function why ?
                 var selectedItem = grid.dataItem(grid.select());
                 var selectedJobNo = selectedItem.jobNo ;
                 alert("selectedJobNo :"+selectedJobNo  );

                $('<input required name="' + options.field + '"/>')
                    .appendTo(container)
                    .kendoDropDownList({
                        autoBind: false,
                        dataTextField: "text",
                        dataValueField: "value",
                        filter: "contains",
                        dataSource: {
                            dataType: "json",                                 
                            transport: {
                                // I need to pass the selected jobNo in order to get the only aprropriate descrption for that jobNo
                                // each row job has description and I don't want to show all the description for all jobs , I need only for that row jobNo
                                 read: "getDescriptionForEachDocumentIndex?selectedJobNo"+selectedJobNo 
                            }
                        }
                          });
                }

一旦网格行处于编辑模式,我需要将选中的行jobNo传递给kendoDropDownList,以便仅用该jobNo的相关描述进行响应。问题是我不能在编辑模式下调用网格,并使用函数grid.select()。在这种情况下该怎么做?

这很简单。编辑器函数的第二个参数有一个名为model的属性,它是用户正在编辑的当前行的dataItem。所以在你的情况下,我想这是可行的:

function descriptionDropDownEditor(container, options) {
    var selectedItem = options.model;

但是,要回答您的问题,您不能访问select()方法,因为grid不是剑道网格对象,它实际上是#grid元素。您可以在小部件初始化的末尾添加.data("kendoGrid"):

$("#grid").kendoGrid({ ... }).data("kendoGrid");

或者在函数内部调用:

function descriptionDropDownEditor(container, options) {
    var gridWidget = $(grid).data("kendoGrid");
    var selectedItem = gridWidget.dataItem(gridWidget.select());