如何使用角度js点燃ui网格中的自定义编辑器提供程序

时间:2016-07-22 07:03:09

标签: angularjs infragistics ignite-ui iggrid

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

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

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

provider.createEditor is not a function

请帮帮我

1 个答案:

答案 0 :(得分:4)

以这种方式编写&#34;编辑提供者&#34; value将被评估为字符串。为了将表达式解析为对象,您需要将其括在{{}}(双花括号)中。然而声明&#34; new $ .ig.EditorProviderNumber()&#34;将不会被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>