question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataTable: Global FilterFunction Broken

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
tandraschkocommented, Feb 6, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found