javascript Primefaces p:datatable - 更改 {CurrentPageReport}
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5453863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Primefaces p:datatable - Change {CurrentPageReport}
提问by Ioannis K.
I`m searching and searching but I can not find anything to solve my problem. I use a DataTable (Primefaces) and wondered how I can change the language/output of some fields.
我正在搜索和搜索,但找不到任何可以解决我的问题的方法。我使用 DataTable (Primefaces) 并想知道如何更改某些字段的语言/输出。
More precisely, I want to change the {CurrentPageReport} in PaginatorTemplate. Now, it looks very simple: (0 of 100). I want to have it like this (Page 0 of 100, 500 results).
更准确地说,我想更改 PaginatorTemplate 中的 {CurrentPageReport}。现在,它看起来很简单:(0 of 100)。我想要这样(第 0 页,共 100、500 个结果)。
I tried a lot, but nothing works. The last I did was:
我尝试了很多,但没有任何效果。我最后做的是:
function change_text () {
$(".ui-paginator-current").each (function() {
$(this).html("Simple test");
});
}
$(".ui-icon").each(
function(index) {
$( this ).bind ("click",function(){ change_text (); });
}
);
(ui-icon is part of each button in the table.)
(ui-icon 是表格中每个按钮的一部分。)
But this is not really effective as you can see :-) This solution works half-way. When I press on a button (next page, previous page) the text in .ui-paginator-current field changes back to the default template. I know.. the reason is because this field is also being reloaded.
但是正如您所看到的那样,这并不是真正有效:-) 此解决方案仅适用于一半。当我按下按钮(下一页,上一页)时,.ui-paginator-current 字段中的文本会变回默认模板。我知道.. 原因是这个字段也被重新加载。
I also tried to change Primefaces Code but I can`t find the correct code area.
我也尝试更改 Primefaces 代码,但找不到正确的代码区域。
I am working with JSF 2.0.3 and PrimeFaces 2.2.1. How can I solve my problem? Can I load paginatorTemplate from a bean? It would really help me if I could change the text from "0 of 100" to "0 aus 100" (german).
我正在使用 JSF 2.0.3 和 PrimeFaces 2.2.1。我该如何解决我的问题?我可以从 bean 加载 paginatorTemplate 吗?如果我可以将文本从“0 of 100”更改为“0 aus 100”(德语),那真的对我有帮助。
Hope you guys can help me, like every time I have a problem.
希望你们能帮助我,就像每次我遇到问题一样。
Ioannis K.
扬尼斯·K。
回答by Ioannis K.
Found it:
找到了:
<p:dataTable currentPageReportTemplate="{currentPage} #{loc.of} {totalPages}" />
for those who are interested in it :-)
对于那些对此感兴趣的人:-)
*Now: I have it like this:
*现在:我有这样的:
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="(Entries: {startRecord} - {endRecord} of {totalRecords}, Page: {currentPage}/{totalPages})"
Hope this helps you guys!
希望这对你们有帮助!
回答by Mark
I haven't tested it but PrimeFaces does support German locale. Have you tried setting the locale in your bean to see if "0 of 100" changes to "0 aus 100" ?
我还没有测试过,但 PrimeFaces 确实支持德语语言环境。您是否尝试在 bean 中设置语言环境以查看“0 of 100”是否更改为“0 aus 100”?
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale("de"));