Support the ongoing development of Laravel.io →
Requests Database Views
Last updated 2 years ago.
0

It works!!! :-)

I only changed my LogicalsController@index and the ajax-code a bit, and thats all.

LogicalsController@index

public function index(Request $request)
    {
        if ($request->ajax()) {
            $nextPageNum = $request['nextPageNum'];
            $order = $request['order'];
            $logicals = Logical::orderBy('logical', $order)->paginate(15, ['*'], 'page', $nextPageNum);
            return response()->json(View::make('logicals.partials.tableForStartpage', ['logicals' => $logicals])->render());
        } else {
            $logicals = Logical::orderBy('logical', 'asc')->paginate(15);
            return view('logicals.index', ['logicals' => $logicals]);
        }
    }

logicals\index.blade.php

@extends('layouts.layout')

@section('content')
    <script>
        var orderLogicals = '{{ route('orderAjax') }}';
        var paginationLink = '{{ route('index') . '/' }}';
        var playUrl = '{{ route('play', [0]) }}';
    </script>

    <body>
        <aside class="container col-md-2">
            ...
        </aside>
        <section id="tableForStartpage" class="main col-md-10">
            @include('logicals.partials.tableForStartpage')
        </section>
    </body>
@endsection

logicals\partials\tableForStartpage

<table id="logicalsTable" class="logicals table table-striped" data-pagenum="{{ $logicals->currentPage() }}">
    {{ csrf_field() }}
    <thead><tr><th data-label="logical">
            Logical<i class="fa fa-sort-alpha-asc order" data-order="asc" aria-hidden="true"></i>
        </th></tr></thead>
    <tbody>
    @foreach($logicals as $logical)
        <tr>
            <td><a href="{{ URL('play', [$logical->id]) }}">{{ $logical->logical }}</a></td>
        </tr>
    @endforeach
    </tbody>
</table>
<div class="pagination">
    {{--uses the template in views\vendor\pagination\default.blade.php--}}
    {{--published with: php artisan vendor:publish--}}
    {{ $logicals->links() }}
</div>

and finally the ajax

$.ajax({
            url: paginationLink,
            method: 'POST',
            data: {
                nextPageNum: nextPageNum,
                order: order,
                _token: $('table').find('input[name="_token"]').val(),
            },
            success: function (response) {
                $('#tableForStartpage').html(response);
                $('#logicalsTable').find('thead').find('i')
                    .attr('data-order', order)
                    .removeClass(oldOrder)
                    .addClass(order);
            }
        });
0

Sign in to participate in this thread!

Eventy

Your banner here too?

getit81 getit81 Joined 30 Aug 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.