Git Product home page Git Product logo

Comments (3)

imacrayon avatar imacrayon commented on June 24, 2024 1

You could try splitting the two merge strategies across nested containers like this:

<form>…</form>
<div id="posts" x-merge="replace">
   <div id="pages" x-merge="append" class="grid…">
        @foreach ($posts as $post)
            <article class="h-[50vh] border">
                <p>{{ $post->title }}</p>
            </article>
        @endforeach
    </div>
    <div id="pagination">…</div>
</div>

Your filter form would target posts and the pagination would target pages pagination.

from alpine-ajax.

n355 avatar n355 commented on June 24, 2024

Great, it works. Thanks for the quick reply and the example.
Here's the result:

<main>

    {{-- Filter --}}
    <form action="/posts"
        x-target="posts">
        @csrf
        <select name="filter"
            x-on:change="$el.form.requestSubmit()">
            <option value="">All</option>
            <option value="Active">Active</option>
            <option value="Inactive">Inactive</option>
        </select>
    </form>

    {{-- Posts --}}
    <div id="posts"
        x-merge="replace">

        {{-- Pages --}}
        <div id="pages"
            x-merge="append">
            @foreach ($posts as $post)
                <article>
                    <p>{{ $post->title }}</p>
                </article>
            @endforeach
        </div>

        {{-- Pagination --}}
        @if ($posts->currentPage() < $posts->lastPage())
            <div id="pagination"
                x-intersect="$ajax(`/posts?filter={{ $filter }}&page={{ $posts->currentPage() + 1 }}`)"
                x-target="pages pagination">
                Loading...
            </div>
        @endif

    </div>

</main>

from alpine-ajax.

imacrayon avatar imacrayon commented on June 24, 2024

Awesome! Thanks for reaching out. If you have any ideas how we might be able to make x-merge more clear in the docs I’d be open to a PR.

from alpine-ajax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.