在Dojo EnhancedGrid FilterBar上设置状态文本

时间:2013-11-14 04:27:06

标签: javascript dojo dojox.grid

EnhancedGrid上的FilterBar有一个标签显示“未应用过滤器”,“显示100个项目中的0个”等。

有没有办法可以通过编程方式将此文本更改为我想要的任何内容?

谢谢,
特里斯坦

编辑: Ken的方法对我很有用,但对于那些需要它的人来说,可能还有另一种方法:Replacing Dojo/Dijit NLS strings

2 个答案:

答案 0 :(得分:3)

您要自定义的字符串是dojox/grid/enhanced/nls/Filter本地化套件的一部分。对此包的引用会存储在Filter插件本身的构造函数中(例如1.9.1中的here)。

自定义这些消息的最可重用且最不易变通的方法可能是创建Filter插件的扩展并相应地更改nls对象。例如:(以下假设您需要dojo/_base/declaredojo/_base/langdojox/grid/EnhancedGriddojox/grid/enhanced/plugins/Filter适当的变量

var CustomFilter = declare(Filter, {
    name: 'customFilter',
    constructor: function () {
        // Avoid modifying the original nls bundle
        this.nls = lang.clone(this.nls);
        // Alter the "no filter applied" message
        this.nls.filterBarMsgNoFilterTemplate = 'Custom message here';
        // Alter other messages here
    }
});

EnhancedGrid.registerPlugin(CustomFilter);

然后,当您创建EnhancedGrid实例时,不是在filter哈希中指定plugins密钥,而是指定customFilter。它的属性将保持不变,因为您仍在扩展原始插件。

如果您需要在nls对象中找出要自定义的邮件的密钥,请查看the source for the bundle that defines them

当然,请注意,通常会根据浏览器的区域设置加载不同的本地化包。上面的示例假设您只关心使用自定义支持一种语言;如果你想支持多个,你可能想要设置自己的nls资源集合,以便在第一个资源之上混合使用。如果你需要帮助我可以扩展这个答案,但这至少应该让你开始。

答案 1 :(得分:0)

要以编程方式更改文本“No Filter applied”,您可以这样做。 我已在网格中测试过它,我实际上正在研究它。

首先获取dom Node,其中定义了Text:

var node = JSON.stringify(dom.byId("dojox_grid_enhanced_plugins_filter_FilterBar_0"));

然后搜索span-tag的类,定义文本并更改它:

dojo.query( '.dojoxGridFBarStatus' ).forEach(function(node){ 
  node.innerHTML = "Set in the Text you would prefer";
 }

您可以使用标签“100个项目中的0个”的文本进行操作。 除非您的更改必须在定义过滤器后进行。

以下是Grid中过滤器栏后面的代码。(由FF Web-DeveloperTool捕获)

<tbody>
<tr>
    <td class=\"dojoxGridFBarBtnTD\">
    <span aria-label=\"Tabelle filtern\" 
            title=\"Filter definieren\" 
            widgetid=\"dijit_form_Button_12\" 
            class=\"dijit dijitReset dijitInline dijitButton dojoxGridFBarBtn\" 
            role=\"presentation\">
                <span class=\"dijitReset dijitInline dijitButtonNode\" 
                data-dojo-attach-event=\"ondijitclick:_onClick\" 
                role=\"presentation\">
                    <span style=\"-moz-user-select: none;\" 
                    id=\"dijit_form_Button_12\" 
                    tabindex=\"0\" 
                    class=\"dijitReset dijitStretch dijitButtonContents\" 
                    data-dojo-attach-point=\"titleNode,focusNode\" 
                    role=\"button\" 
                    aria-labelledby=\"dijit_form_Button_12_label\">
                        <span class=\"dijitReset dijitInline dijitIcon dojoxGridFBarDefFilterBtnIcon\" 
                        data-dojo-attach-point=\"iconNode\">
                        </span>
                            <span class=\"dijitReset dijitToggleButtonIconChar\">?</span>
                            <span class=\"dijitReset dijitInline dijitButtonText\" 
                            id=\"dijit_form_Button_12_label\" 
                            data-dojo-attach-point=\"containerNode\">...</span>
                    </span>
                </span>
            <input value=\"\" 
            class=\"dijitOffScreen\" 
            tabindex=\"-1\"
            role=\"presentation\" 
            data-dojo-attach-point=\"valueNode\" 
            type=\"button\">
    </span>
    </td>
    <td class=\"dojoxGridFBarInfoTD\">
        <span class=\"dojoxGridFBarInner\">
            <span class=\"dojoxGridFBarStatus\" 
            dojoattachpoint=\"statusBarNode\">Kein Filter angewendet</span>
                <span aria-label=\"Filter abwählen\" 
                style=\"display: none;\" 
                widgetid=\"dijit_form_Button_13\" 
                class=\"dijit dijitReset dijitInline dijitButton dojoxGridFBarClearFilterBtn\" 
                role=\"presentation\">
                    <span class=\"dijitReset dijitInline dijitButtonNode\" 
                    data-dojo-attach-event=\"ondijitclick:_onClick\" 
                    role=\"presentation\">
                        <span style=\"-moz-user-select: none;\" 
                            id=\"dijit_form_Button_13\" 
                            tabindex=\"0\" 
                            class=\"dijitReset dijitStretch dijitButtonContents\" 
                            data-dojo-attach-point=\"titleNode,focusNode\" 
                            role=\"button\" 
                            aria-labelledby=\"dijit_form_Button_13_label\">
                                <span class=\"dijitReset dijitInline dijitIcon dojoxGridFBarClearFilterBtnIcon\" 
                                    data-dojo-attach-point=\"iconNode\">
                                </span>
                                <span class=\"dijitReset dijitToggleButtonIconChar\">?</span>
                                    <span class=\"dijitReset dijitInline dijitButtonText\" 
                                        id=\"dijit_form_Button_13_label\" 
                                        data-dojo-attach-point=\"containerNode\">Filter löschen</span>
                                    </span>
                        </span>
                        <input value=\"\" 
                        class=\"dijitOffScreen\" 
                        tabindex=\"-1\" 
                        role=\"presentation\" 
                        data-dojo-attach-point=\"valueNode\" 
                        type=\"button\">
                    </span>
                    <span widgetid=\"dijit_form_Button_14\" 
                    class=\"dijit dijitReset dijitInline dijitButton dojoxGridFBarCloseBtn\" 
                    role=\"presentation\">
                        <span class=\"dijitReset dijitInline dijitButtonNode\" 
                        data-dojo-attach-event=\"ondijitclick:_onClick\" 
                        role=\"presentation\">
                            <span style=\"-moz-user-select: none;\" 
                            title=\"Filterleiste schließen\" 
                            id=\"dijit_form_Button_14\" 
                            tabindex=\"0\" 
                            class=\"dijitReset dijitStretch dijitButtonContents\" 
                            data-dojo-attach-point=\"titleNode,focusNode\" 
                            role=\"button\" 
                            aria-labelledby=\"dijit_form_Button_14_label\">
                                <span class=\"dijitReset dijitInline dijitIcon dojoxGridFBarCloseBtnIcon\" 
                                data-dojo-attach-point=\"iconNode\">
                                </span>
                                    <span class=\"dijitReset dijitToggleButtonIconChar\">?
                                    </span>
                                        <span class=\"dijitReset dijitInline dijitButtonText dijitDisplayNone\" 
                                        id=\"dijit_form_Button_14_label\" 
                                        data-dojo-attach-point=\"containerNode\">Filterleiste schließen
                                        </span>
                            </span>
                        </span>
                        <input value=\"\" 
                        class=\"dijitOffScreen\" 
                        tabindex=\"-1\" 
                        role=\"presentation\" 
                        data-dojo-attach-point=\"valueNode\" 
                        type=\"button\">
                    </span>
                </span>
    </td>
</tr>
</tbody>

希望对你有所帮助。

此致,Miriam