在 Dojo 增强网格筛选器栏上设置状态文本
Set the status text on a Dojo EnhancedGrid FilterBar
网格上的过滤器栏有一个标签,显示"未应用过滤器","显示 100 个项目中的 0 个"等。
有没有办法以编程方式将此文本更改为我想要的任何内容?
谢谢
特里斯坦
编辑:Ken 的方法对我来说效果很好,但对于那些需要它的人来说,这里可能有另一种方法:替换 Dojo/Dijit NLS 字符串
您要自定义的字符串是dojox/grid/enhanced/nls/Filter
本地化捆绑包的一部分。 对此捆绑包的引用存储在Filter
插件本身的构造函数中(例如,在 1.9.1 中)。
自定义这些消息的最可重用且波动性最小的方法可能是创建 Filter 插件的扩展并相应地更改nls
对象。 例如:(以下假设您需要对适当的变量进行dojo/_base/declare
、dojo/_base/lang
、dojox/grid/EnhancedGrid
和dojox/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>
希望对您有所帮助。
问候,米里亚姆
- 根据文件内容设置状态
- 设置状态PubSub ReactJS和Rails
- jquery在不触发更改事件的情况下切换设置状态
- Node.js中的垃圾收集作用域-变量将保持设置状态多长时间
- Angular JS-UI路由器页面重载获胜't设置状态
- 在 Dojo 增强网格筛选器栏上设置状态文本
- 反应本机,错误地设置状态中的项目值
- 设置状态 [反应本机] 后无法编辑输入文本
- 如何在 React 中从子组件设置状态
- PassportJS - 动态设置状态以允许在回调时重定向
- 在 $.get 中设置状态
- 如何为嵌套对象设置状态
- React-设置状态并同时获取值
- 道具未设置状态
- 使用React中的循环从JSON数组中获取数据并根据数据设置状态
- React:在设置状态之前启动初始渲染(通过ajax)
- Reactjs:设置状态与复选框:选中或未选中
- 如何在react中设置状态为新数据
- 在SignalR的客户端设置状态变量
- 当抛出错误时,反应本机提取无法设置状态