ExtJS 4>行编辑器网格>如何更改“更新”按钮文字

发布于 2024-12-09 08:17:37 字数 40 浏览 0 评论 0原文

有没有办法更改 ExtJS-4 行编辑器网格中“更新”按钮的文本?

Is there any way to change the text of "Update" button in ExtJS-4 Row Editor Grid ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

诗化ㄋ丶相逢 2024-12-16 08:17:37

好问题,我查看了源代码,虽然 RowEditing 插件中没有任何内容,但在它扩展“RowEditor.js”的类中,有以下内容:

Ext.define('Ext.grid.RowEditor', {
    extend: 'Ext.form.Panel',
    requires: [
        'Ext.tip.ToolTip',
        'Ext.util.HashMap',
        'Ext.util.KeyNav'
    ],

    saveBtnText  : 'Update',
    cancelBtnText: 'Cancel',
    ...
});

所以我假设您只需要覆盖 < code>'saveBtnText' 在 'Ext.grid.plugin.RowEditing' 实例中,因为它使用 callParent(arguments) 调用父构造函数RowEditing

Good question, I had a look through the source code and whilst there is nothing inside the RowEditing plugin, in the class it extends 'RowEditor.js' there is the following:

Ext.define('Ext.grid.RowEditor', {
    extend: 'Ext.form.Panel',
    requires: [
        'Ext.tip.ToolTip',
        'Ext.util.HashMap',
        'Ext.util.KeyNav'
    ],

    saveBtnText  : 'Update',
    cancelBtnText: 'Cancel',
    ...
});

So I'd assume you'd just need to override the 'saveBtnText' in your instance of 'Ext.grid.plugin.RowEditing' as it calls the parent constructor with callParent(arguments) in the RowEditing class

霊感 2024-12-16 08:17:37

没那么容易,而且没有在无证区域进行黑客攻击。问题是,Ext.grid.plugin.RowEditing 直接实例化 Ext.grid.RowEditor,而不允许您传入配置选项。因此,一般来说,您必须重写插件中的 initEditor() 方法并实例化您自己的行编辑器:

// ...
plugins: [{
    ptype: 'rowediting',
    clicksToEdit: 2,
    initEditor: function() {
        var me = this,
            grid = me.grid,
            view = me.view,
            headerCt = grid.headerCt;

        return Ext.create('Ext.grid.RowEditor', {
            autoCancel: me.autoCancel,
            errorSummary: me.errorSummary,
            fields: headerCt.getGridColumns(),
            hidden: true,

            // keep a reference..
            editingPlugin: me,
            renderTo: view.el,
            saveBtnText: 'This is my save button text', // <<---
            cancelBtnText: 'This is my cancel button text' // <<---
        });
    },
}],
// ...

Not that easy and not without hacking in undocumented areas. The problem is, that the Ext.grid.plugin.RowEditing directly instantiates the Ext.grid.RowEditor without allowing you to pass in configuration options. So in general you have to override the initEditor() method in the plugin and instantiate your own row editor:

// ...
plugins: [{
    ptype: 'rowediting',
    clicksToEdit: 2,
    initEditor: function() {
        var me = this,
            grid = me.grid,
            view = me.view,
            headerCt = grid.headerCt;

        return Ext.create('Ext.grid.RowEditor', {
            autoCancel: me.autoCancel,
            errorSummary: me.errorSummary,
            fields: headerCt.getGridColumns(),
            hidden: true,

            // keep a reference..
            editingPlugin: me,
            renderTo: view.el,
            saveBtnText: 'This is my save button text', // <<---
            cancelBtnText: 'This is my cancel button text' // <<---
        });
    },
}],
// ...

对于 ExtJS 4

Ext.grid.RowEditor.prototype.cancelBtnText = "This is cancel";
Ext.grid.RowEditor.prototype.saveBtnText = "This is update";

For ExtJS 4

Ext.grid.RowEditor.prototype.cancelBtnText = "This is cancel";
Ext.grid.RowEditor.prototype.saveBtnText = "This is update";
我是有多爱你 2024-12-16 08:17:37

这个解决方案是定义rowEditors的原型。这意味着这个配置比较一般。
如果您只想为一个编辑器更改它,或者如果您想获得不同的配置,那么原型绝对不是解决方案。

查看源代码:

initEditorConfig: function(){
        var me       = this,
            grid     = me.grid,
            view     = me.view,
            headerCt = grid.headerCt,
            btns     = ['saveBtnText', 'cancelBtnText', 'errorsText', 'dirtyText'],
            b,
            bLen     = btns.length,
            cfg      = {
                autoCancel: me.autoCancel,
                errorSummary: me.errorSummary,
                fields: headerCt.getGridColumns(),
                hidden: true,
                view: view,
                // keep a reference..
                editingPlugin: me
            },
            item;
    for (b = 0; b < bLen; b++) {
        item = btns[b];

        if (Ext.isDefined(me[item])) {
            cfg[item] = me[item];
        }
    }
    return cfg;
}`

此方法初始化 rowEditor,并且 btns 数组上有一个循环:

btns 数组:

btns = ['saveBtnText', 'cancelBtnText', 'errorsText', 'dirtyText']    

for (b = 0; b < bLen; b++) {
        item = btns[b];

        if (Ext.isDefined(me[item])) {
            cfg[item] = me[item];
        }
    }

在这个循环中,对于 btnArray 中的每个字符串,将搜索 cfg 中是否存在相同的字符串属性,如果找到,则将其添加到配置中。您只需管理该循环找到您想要修改的内容:

示例:我们想要更改保存按钮的文本:

作为 btns 数组的第一项的属性 saveBtnText 必须存在于 cfg 中:

if (Ext.isDefined(me[item])) {
 cfg[item] = me[item];
}

如果属性存在,则进行此搜索:< code>if (Ext.isDefined(me[item]))

如果 saveBtnText 已存在于 rowEditor 属性中,则:

cfg[item] = me[item];

并且将设置附加配置属性!

This solution is to define the prototype of rowEditors. that means that this config is than general.
If you want to change it just for one editor, or if you want to get different configs , the prototype is definitely not the solution.

look at source code :

initEditorConfig: function(){
        var me       = this,
            grid     = me.grid,
            view     = me.view,
            headerCt = grid.headerCt,
            btns     = ['saveBtnText', 'cancelBtnText', 'errorsText', 'dirtyText'],
            b,
            bLen     = btns.length,
            cfg      = {
                autoCancel: me.autoCancel,
                errorSummary: me.errorSummary,
                fields: headerCt.getGridColumns(),
                hidden: true,
                view: view,
                // keep a reference..
                editingPlugin: me
            },
            item;
    for (b = 0; b < bLen; b++) {
        item = btns[b];

        if (Ext.isDefined(me[item])) {
            cfg[item] = me[item];
        }
    }
    return cfg;
}`

this method inits the rowEditor, and there's a loop on btns Array:

btns Array :

btns = ['saveBtnText', 'cancelBtnText', 'errorsText', 'dirtyText']    

for (b = 0; b < bLen; b++) {
        item = btns[b];

        if (Ext.isDefined(me[item])) {
            cfg[item] = me[item];
        }
    }

In this loop foreach string in btnArray it's searched if exists in cfg the same string property, if it's found it's added to config. You just have to manage that this loop finds what you want to modify:

Example: we want to change the text of save button:

the property saveBtnText which is the first item of btns Array must exists in cfg:

if (Ext.isDefined(me[item])) {
 cfg[item] = me[item];
}

this search if property exists : if (Ext.isDefined(me[item]))

if saveBtnText already exists in rowEditor properties then:

cfg[item] = me[item];

and the additional config property will be set!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文