XF 2.1 How do I get the filter_macros with prefix filter working?

cmpe

Active member
I created a new entity and trying to allow admins to crud the entity through admin controller. I suspect I will have over 300 of these entities so using the filter_macros in the template to allow admin to filter by string.

So when using this without the "prefix" checked, the datalist gets updated properly with the filtered list. :)

However when I have prefix checked, the datalist doesn't show anything. o_O Using chrome tools, I can see that the browser is making an ajax call and it looks like it's fetching the proper response with the items however this does not show up in the datalist.

PHP:
            <xf:macro template="filter_macros" name="quick_filter"
                arg-key="entity"
                arg-ajax="{{ link('myaddon/entity') }}"
                arg-class="block-outer-opposite" />

In the backend, I'm using finder and whereOr with prefixMatch condition:
PHP:
    public function searchEnt($match, $prefixMatch = false)
    {
            if (strlen($match))
            {
                    $this->whereOr(
                            [
                                $this->columnUtf8('ent_name'),
                                'LIKE',
                                $this->escapeLike($match, $prefixMatch ? '?%' : '%?%')
                            ],
                            [
                                $this->columnUtf8('ent_abbr'),
                                'LIKE',
                                $this->escapeLike($match, $prefixMatch ? '?%' : '%?%')
                            ]
                    );
            }
            return $this;
    }

I've looked at examples of this in phrase_list and template_list and so on and still can't figure out why this isn't working for my entity.

Any help would be appreciated.

thanks!
 
Last edited:
Solution
Figured it out. Had to poke around with xf/filter.js to troubleshoot since I noticed the datarow items that I expected to be visible had "is-hidden" class being added and realized the regex test condition was failing in JS.

I had something like...

cmpe

Active member
Figured it out. Had to poke around with xf/filter.js to troubleshoot since I noticed the datarow items that I expected to be visible had "is-hidden" class being added and realized the regex test condition was failing in JS.

I had something like this in my template:
PHP:
                        <xf:datarow>
                            <xf:cell href="{{ link('myaddon/entity/edit', $entity) }}">
                                {$entity.name}
                            </xf:cell>
                            <xf:cell>
                                {$entity.abbr}
                            </xf:cell>
                        </xf:datarow>

So the regex match was failing due to the whitespace in front of the string I was trying to match.
 
Solution
Top