在 Dojo 增强网格筛选器栏上设置状态文本

Set the status text on a Dojo EnhancedGrid FilterBar

本文关键字:设置 状态 文本 Dojo 增强 网格 筛选      更新时间:2023-09-26
增强

网格上的过滤器栏有一个标签,显示"未应用过滤器","显示 100 个项目中的 0 个"等。

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

谢谢
特里斯坦

编辑:Ken 的方法对我来说效果很好,但对于那些需要它的人来说,这里可能有另一种方法:替换 Dojo/Dijit NLS 字符串

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

自定义这些消息的最可重用且波动性最小的方法可能是创建 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 实例时,无需在 plugins 哈希中指定 filter 键,而是指定customFilter。 它的属性将保持不变,因为您仍在扩展原始插件。

如果您需要找出要自定义的消息的 nls 对象中的键,请查看定义它们的捆绑包的来源。

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

要以编程方式更改文本"未应用过滤器",您可以这样做。我已经在我实际工作的网格中对其进行了测试。

首先获取 dom 节点,其中定义了 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 个"的文本执行相同的操作。除了必须在定义筛选器之后进行更改。

下面是网格中筛选器栏后面的代码。(由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>

希望对您有所帮助。

问候,米里亚姆