ahmet
ahmet

Reputation: 1125

How to change default p:dataTable emptyMessage message

I am using PrimeFaces' dataTable. I get "No records found." when table has no element. I want to change this message to something like "No result" and make this message i18n type.

I don't want to use

<p:dataTable 
    id="idTable" 
    ...
    emptyMessage="#{messages['general.message.EmptyList']}"
>

for every table.

How can I change p:dataTable default emptyMessage message?

Upvotes: 24

Views: 29025

Answers (2)

luisja19
luisja19

Reputation: 27

write emptyMessage="" inside the datatable Ej:

<p:dataTable var="hola"
    value="#{logica.hola}"
    emptyMessage="text you want to appear" >
    </p:dataTable>

Upvotes: -1

BalusC
BalusC

Reputation: 1109865

From the PrimeFaces 3.5 DataTable source code:

210    public java.lang.String getEmptyMessage() {
211        return (java.lang.String) getStateHelper().eval(PropertyKeys.emptyMessage, "No records found.");
212    }

So, it's hard coded and there's no way to change it in a single place other way than hacking the PrimeFaces source or creating a tagfile (not composite!) <my:dataTable> which wraps the <p:dataTable> with the desired message set.

<ui:composition ...>
    <p:dataTable id="#{id}" value="#{value}" var="item" 
        emptyMessage="#{messages['general.message.EmptyList']}">
        <ui:insert />
    </p:dataTable>
</ui:composition>
<my:dataTable id="foo" value="#{bean.items}">
    <p:column>#{item.foo}</p:column>
    <p:column>#{item.bar}</p:column>
</my:dataTable>

If you actually don't want to change the message, but merely want to hide it altogether, then you could also opt for a pure CSS solution:

.ui-datatable-empty-message {
    display: none;
}

Upvotes: 39

Related Questions