Partial with filters AND pagination

Hi There,

Does somebody have a working example of the partial that can be filtered from outside and has a pagination which doesn’t reset filters?

Both those features work perfectly as long as kept separate. Unfortunately, I didn’t manage to make them work with one another without sending the data everywhere.

example would be:
Page:

<form accept-charset="UTF-8" data-request="onUpdateSearch" data-request-update="'jobs/job-list': '#job-display'">
    <div class="row">
        <div class="col-lg-6">
            <input type="text" name="keywords" placeholder="Keywords" value="{{ searchQuery.keywords }}">
        </div>
    </div>
</form>

<section>
    <div id="job-display">
        {% partial "jobs/job-list" searchQuery=searchQuery %}
    </div>
</section>

Page code

function onUpdateSearch() {
    $this['searchQuery'] = Input();
}

then the partial

<span>{{ jobs.appends( data_from_get ).fragment('top-pagination').render | raw }}</span>
{% for job in jobs | sort((a, b) => a.distanceFrom <=> b.distanceFrom) %}
    job display
{% endfor %}
function onStart() {
    Jobs::where('keyword', 'LIKE', $this['searchQuery']['keywords'])->paginate(10)->get()
}

How can I preserve ‘searchQuery’, so the filter doesn’t reset on page change?

I’ve tried with ajaxPartials and pager() - examples of those would be much appreciated as well!

1 Like