Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces: How to get datatable column filter component

Is there a solution to set a "DefaultValue" for the "filterBy" Component ?? I mean more precisely ... How can I set the value of the component shown in the picture ?

http://www.pictureupload.de/originals/pictures/111012170732_primefaces.png

Or how can I set a defaultValue for the option "filtering" in the p:column?!

            <p:column id="artikelVerkaufDatum" headerText="Datum" filterBy="#{sales.dateForFilter}"
                filterMatchMode="startsWith">
                <h:outputText id="date" value="#{sales.datum}">
                    <f:convertDateTime type="date" pattern="dd.MM.yyyy HH:MM:ss" />
                </h:outputText>
            </p:column>

Ok ... another question ... My FireBug says that the component exists with ... but i cannot access it with for example: something like FacesContext.getCurrentInstance().getViewRoot().findComponent ... I always get a NullpointerException :(

<th id="artikelVerkauf:datatable:artikelVerkaufDatum" class="ui-state-default ui-filter-column" role="columnheader">
<div class="ui-dt-c">
<span>Datum</span>
<input id="artikelVerkauf:datatable:artikelVerkaufDatum_filter" class="ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" autocomplete="off" value="" name="artikelVerkauf:datatable:artikelVerkaufDatum_filter" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false">
</div>
</th>

If anybody has any idea ... please let me know ! every help is welcomed :) Regards Sway

like image 680
Sway Avatar asked Mar 25 '26 20:03

Sway


1 Answers

This is a solution I used once (PF 3.5):

  • First set widgetVar="tableWidget" for the datatable.
  • Assign a filterStyleClass="my-column-filter" for the p:column that is filtered
  • Then insert the following JavaScript which will be executed after the DOM is ready:

    $( document ).ready(function() { $('.my-column-filter').val('default'); tableWidget.filter(); });

Good luck!

like image 59
alfonx Avatar answered Mar 28 '26 10:03

alfonx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!