EnhancedGrid 上的 FilterBar 有一个标签,显示“未应用过滤器”、“显示 100 个项目中的 0 个”等。
有没有办法以编程方式将此文本更改为我想要的任何内容?
谢谢,
特里斯坦
编辑:Ken 的方法对我来说效果很好,但对于那些需要它的人来说,这里可能还有另一种方法:替换 Dojo/Dijit NLS 字符串
EnhancedGrid 上的 FilterBar 有一个标签,显示“未应用过滤器”、“显示 100 个项目中的 0 个”等。
有没有办法以编程方式将此文本更改为我想要的任何内容?
谢谢,
特里斯坦
编辑:Ken 的方法对我来说效果很好,但对于那些需要它的人来说,这里可能还有另一种方法:替换 Dojo/Dijit NLS 字符串
您要自定义的字符串是dojox/grid/enhanced/nls/Filter
本地化包的一部分。对该包的引用存储在Filter
插件本身的构造函数中(例如,在 1.9.1 中)。
自定义这些消息的最可重用和最不稳定的方法可能是创建过滤器插件的扩展并nls
相应地更改对象。例如:(以下假设您需要dojo/_base/declare
、dojo/_base/lang
、dojox/grid/EnhancedGrid
和dojox/grid/enhanced/plugins/Filter
to 适当的变量)
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
对象中要自定义的消息的键,请查看定义它们的包的源。
当然,请注意,通常会根据浏览器的区域设置加载不同的本地化包。上面的示例假设您只关心通过自定义支持一种语言;如果您想支持多个,您可能希望设置自己的一组 nls 资源以混合在第一个资源之上。如果您需要帮助,我可以扩展此答案,但这至少应该让您入门。
要以编程方式更改文本“未应用过滤器”,您可以这样做。我已经在我实际工作的网格中对其进行了测试。
首先获取定义Text的dom节点:
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>
希望对您有所帮助。
问候,米里亚姆