kendoui网格,默认模板和编辑器

kendo-ui grid, default templates and editors

本文关键字:编辑器 默认 网格 kendoui      更新时间:2023-09-26

我在durandal项目中工作,喜欢使用你的剑道ui网格。

在我的项目中,我需要动态地构建网格列阵列。即,我(通过ajax请求)获得关于每个网格列的信息的数据数组,并通过在数据数组上循环来构建网格。

这是我的代码:

   function initGrid(formInfo, FormFieldsInfo) {
        //=========================================
        //region: build dinamic fridColumns, gridSchema
        //=========================================
        var columns = [];
        var fields = {};
        var primaryKey = null;
        $.each(FormFieldsInfo, function addGridColumn(index, fieldInfo) {
            var column = {};
            column.field = fieldInfo.FieldName;
            column.headerTemplate = "<span class='headerGrid-att'>" + fieldInfo.DisplayTitle + "</span>";
            column.attributes = { "class": "columnBorder" };
            column.template = getColumnTemplate(fieldInfo.ComponentType, fieldInfo.FieldName);
            column.editor = getColumnEditor(fieldInfo.ComponentType);
            columns.add(column);
            var field = {};
            field.type = global.enums.fieldType[fieldInfo.FieldType];
            field.editable = true;
            fields[fieldInfo.FieldName] = field;
            if (fieldInfo.isKey == true) {
                primaryKey = fieldInfo.FieldName;
            }
        });
        vm.grid.gridOptions.columns = columns;
        vm.grid.schema = {
            data: 'Data',
            model: {
                id: primaryKey,
                fields: fields
            }
        };
        var dataQuery = {
            UserNo: global.cache.get(global.enums.cacheItems.USER).Id,
            ProcedureName: formInfo.SelectProcedure
        };
        //=========================================
        //end region: build dinamic fridColumns, gridSchema
        //=========================================
        vm.grid.dataSourceUrl = global.webApiConfig.getApiPath(global.enums.httpPath.GetETableGridData.path + '?query=' + JSON.stringify(dataQuery));
        vm.grid.remoteDataSource = true;           
        vm.grid.setDataSource();
        vm.grid.setGridOptionsSetting({ editable: "popup" });
    }
    function getColumnTemplate(type, fieldName) {
        switch (type) {
            case global.enums.componentType.checkBox:
                return function checkBoxTemplate(dataItem) {
                    return vm.grid.activeNotActiveTemplate(dataItem[fieldName])
                };
            case global.enums.componentType.dateTime:
                return function dateTemplate(dataItem) {
                    return vm.grid.ParseDateFormat(dataItem, fieldName)
                };
            default: //simple edit, combo
                return ???
        }
    }
    function getColumnEditor(type, fieldName) {
        switch (type) {
            case global.enums.componentType.date:
                return function dateEditor(container, options) {
                    vm.grid.datePickerEditor(container, options, false);
                }
            case global.enums.componentType.time:
                return function timeEditor(container, options) {
                    vm.grid.inputTimeEditor(container, options, new timeInput())
                }
            default: //simple edit,checkBox, combo
                return ???
        }
    }

我的问题是:

在常规网格中,使用consts列数组,我不会为常规字段(如简单字符串数据)提供任何模板或编辑器,也不会为boolean checkBox列提供任何编辑器。

但是,在这种情况下,我必须始终返回template/editor函数。那么,我能做什么呢?我必须写的反熔丝代码是什么?(我必须在???标记的背面写些什么?)

谢谢!

???替换为undefined,这将使其调用默认方法。