angularjs - 如何使用 Angular JS 在 ignite ui 网格中创建自定义编辑器提供程序

标签 angularjs infragistics ignite-ui iggrid

我正在使用带有 Angular js 的 Ignite UI 网格指令。 我通过扩展 $.ig.EditorProvider 创建自定义编辑器提供程序 并在 html 标记中使用该编辑器作为

<column-setting column-key="comments" editor-provider="new $.ig.EditorProviderNumber()"> 
</column-setting>

但是当我编辑网格时它显示错误

provider.createEditor is not a function

请帮帮我

最佳答案

以这种方式编写的“editor-provider”值将被评估为字符串。为了将表达式解析为对象,您需要将其括在 {{}} (双花括号)中。然而,语句“new $.ig.EditorProviderNumber()”不会被 Angular 1 expression parser 解析。 ,因此您需要使用作用域函数来创建对象。

这是代码:

// This editor provider demonstrates how to wrap HTML 5 number INPUT into editor provider for the igGridUpdating
$.ig.EditorProviderNumber = $.ig.EditorProviderNumber || $.ig.EditorProvider.extend({
    // initialize the editor
    createEditor: function (callbacks, key, editorOptions, tabIndex, format, element) {
        element = element || $('<input type="number" />');
        /* call parent createEditor */
        this._super(callbacks, key, editorOptions, tabIndex, format, element);

        element.on("keydown", $.proxy(this.keyDown, this));
        element.on("change", $.proxy(this.change, this));
        this.editor = {};
        this.editor.element = element;
        return element;
    },
    keyDown: function(evt) {
        var ui = {};
        ui.owner = this.editor.element;
        ui.owner.element = this.editor.element;
        this.callbacks.keyDown(evt, ui, this.columnKey);
        // enable "Done" button only for numeric character
        if ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105)) {
            this.callbacks.textChanged(evt, ui, this.columnKey);
        }
    },
    change: function (evt) {
        var ui = {};
        ui.owner = this.editor.element;
        ui.owner.element = this.editor.element;
        this.callbacks.textChanged(evt, ui, this.columnKey);
    },
    // get editor value
    getValue: function () {
        return parseFloat(this.editor.element.val());
    },
    // set editor value
    setValue: function (val) {
        return this.editor.element.val(val || 0);
    },
    // size the editor into the TD cell
    setSize: function (width, height) {
      this.editor.element.css({
            width: width - 2,
            height: height - 2,
            borderWidth: "1px",
            backgroundPositionY: "9px"
      });
    },
    // attach for the error events
    attachErrorEvents: function (errorShowing, errorShown, errorHidden) {
        // implement error logic here
    },
    // focus the editor
    setFocus: function () {
        this.editor.element.select();
    },
    // validate the editor
    validator: function () {
        // no validator
        return null;
    },
    // destroy the editor
    destroy: function () {
        this.editor.remove();
    }
});

sampleApp.controller('sampleAppCtrl', function ($scope) {
    $scope.getProvider = function () {return new $.ig.EditorProviderNumber()};
});

<column-setting column-key="ProductNumber" editor-provider="{{getProvider()}}"></column-setting>

关于angularjs - 如何使用 Angular JS 在 ignite ui 网格中创建自定义编辑器提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38520176/

相关文章:

javascript - Infragistics 使用 igTextEditor 过滤数字

javascript - AngularJS 的单对象模型

javascript - 不能在 ng-class 上重复相同的条件两次

export-to-excel - 将超过 100000 行导出到 Excel - Infragistics Excel 导出器

jquery - 如何获取igdatachart上y轴的最高值

javascript - Ignite UI 树网格未使用新数据更新表

javascript - JSON AngularJS 多个对象

javascript - $ionicScrollDelegate.scrollTop 卡住页面滚动

winforms - 单击外部时如何从 Infragistics ultragrid 单元中移除焦点?

vb.net - UltraGrid 获取所有单元格