filterdatatableprimefacesjquery-tooltip

how to add placeholder text in the filter box in datatable column headers


I have a prime faces datatable with few columns and have filteryBy attribute for all the columns. How do I add placeholder or watermark to provide hint for users. Any suggestions,will be appreciated thanks!

<p:dataTable var="dt" widgetVar="widgetUserRecords"
                             value="#{userBean.result}"
                             id="userRecordTable" paginator="true"
                             paginatorAlwaysVisible="false" rows="10"
                             height="300" >
<p:column sortBy="#{dt.course.name}" filterStyle="width:50px;"
                              filterBy="#{dt.course.name}" headerText="Course Name" style="text-align:bottom">
    <h:outputText value="#{dt.course.name}"/>
</p:column>
.
. 
.
  (other columns)
</p:dataTable>

Solution

  • First give and ID for your column and add a p:watermark component:

    <h:form id="tableForm">
    ...    
        <p:dataTable var="dt" widgetVar="widgetUserRecords"
                         value="#{userBean.result}"
                         id="userRecordTable" paginator="true"
                         paginatorAlwaysVisible="false" rows="10"
                         height="300" >
    
            <p:column id="column1" sortBy="#{dt.course.name}" filterStyle="width:50px;"
                          filterBy="#{dt.course.name}" headerText="Course Name" style="text-align:bottom">
                <h:outputText value="#{dt.course.name}"/>
                <p:watermark forElement="tableForm:userRecordTable:column1" value="hint..."/>
            </p:column>
    
        </p:dataTable>
    ...
    </h:form>
    

    Don't forget to replace the tableForm id with your actual form around your p:dataTable.