DataTable: Global FilterFunction Broken
See original GitHub issueDescribe the defect Working on a showcase example to put back the old GlobalFilterFunction and the functionality has changed.
<p:dataTable var="customer" value="#{dtFilterView.customers2}" widgetVar="customersTable2"
emptyMessage="No customers found with given criteria"
filteredValue="#{dtFilterView.filteredCustomers2}" filterBy="#{dtFilterView.filterBy}"
globalFilterFunction="#{dtFilterView.globalFilterFunction}">
<f:facet name="header">
<div class="p-text-left">
<h:outputText value="Search all fields using globalFilterFunction:" />
<p:inputText id="globalFilter" onkeyup="PF('customersTable2').filter()" style="width:150px"
placeholder="Enter keyword" />
</div>
</f:facet>
public boolean globalFilterFunction(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (LangUtils.isValueBlank(filterText)) {
return true;
}
int filterInt = getInteger(filterText);
Customer customer = (Customer) value;
return customer.getName().toLowerCase().contains(filterText)
|| customer.getCountry().getName().toLowerCase().contains(filterText)
|| customer.getRepresentative().getName().toLowerCase().contains(filterText)
|| customer.getStatus().name().toLowerCase().contains(filterText)
|| customer.getActivity() < filterInt;
}
its expecting the value
to be the Customer POJO and right now it is just passing it each individual column value as a String which causes java.lang.ClassCastException: java.lang.String cannot be cast to org.primefaces.showcase.domain.Customer
.
The old code was passing the table.RowData();
if (hasGlobalFilter && globalFilterFunction != null) {
globalMatch = (Boolean) globalFilterFunction.invoke(elContext, new Object[]{table.getRowData(), globalFilterValue, filterLocale});
}
But the new code is passing each individual column.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Primefaces Datatable global filtering not working [duplicate]
When I don't search anything, the datatable shows up the data just fine, but if I type anything it'll lose all elements and...
Read more >Global Filter not working - Prime Community Forum
Hello everyone, i'm trying to make a datatable with a globalfilter but it is not working properly. The data is all OK, ...
Read more >Having an issue with a filter not working — DataTables forums
We have multiple filters and we've been working really well with them. I ran into one that doesn't seem to work, and I...
Read more >DataTable custom filter function breaks table #2702 - GitHub
When looking into the code it seems that in components/lib/datatable/DataTable.js:1322 it tries to fetch a function for my custom filter, which in this...
Read more >filter 1 « PrimeFaces « JSF Q&A - Java2s.com
Primefaces DataTable filtering and RowSelection not working stackoverflow.com. I'am new to PrimeFaces. ... Using PrimeFaces Global Filter? stackoverflow.com.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Integration Tests…
Global Filter: https://github.com/primefaces-extensions/primefaces-integration-tests/commit/64d6e5c246ab3735889142a77060e8d3ec6f4451
Global Filter Function: https://github.com/primefaces-extensions/primefaces-integration-tests/commit/18d79fca8a43d45aee64bdc0547c90ab4cec3dee
@melloware @sqores please dont merge such PRs without review before. We must at least clarify what should be the correct behavior and refactor the code for it, not just hackin this behavior, without removing the old behavior.