【问题标题】:How is Data Table Worked?数据表是如何工作的?
【发布时间】:2021-07-09 08:17:04
【问题描述】:

在激活多个 JS 功能时需要帮助,例如显示数据条目、搜索、排序依据和分页。

我正在使用 Laravel 8。

JS 数据表

// Call the dataTables jQuery plugin
$(document).ready(function() {
  $('#dataTable').DataTable();
});

查看刀片

@extends('back.index')

@section('content')
<main>
    ...
                <div class="table-responsive">
                    <table class="table table-bordered table-hover" id="dataTable" width="100%" cellspacing="0">
                        <thead>
                            <tr style="text-align: center;">
                                <th style="width: 10%">#</th>
                                <th style="width: 60%">Nama Kategori</th>
                                <th style="width: 30%">Last Updated</th>
                            </tr>
                        </thead>
                        @forelse ($kategoris as $kategori)
                        <tbody>
                            <tr>
                                <td style="text-align: center;">{{$kategori->id}}</td>
                                <td><a href={{ route('kategoris.show',['kategori' => $kategori->id]) }}>{{$kategori->nama}}</a></td>
                                <td style="text-align: center;">{{$kategori->updated_at}}</td>
                            </tr>
                        </tbody>
                        @empty
                        <strong>Tidak Ada Data ..</strong>
                        @endforelse
                    </table>
                </div>
            </div>
        </div>
   </div>
</main>
@endsection

控制器

<?php

namespace App\Http\Controllers;

use App\Models\Kategori;
use RealRashid\SweetAlert\Facades\Alert;
use Illuminate\Http\Request;

class KategoriController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
        $kategoris = Kategori::all();
        return view('back.kategori.show',['kategoris' => $kategoris]);
    }
  ...
}

如何让它发挥作用? 我真的对这个问题感到困惑,我如何解决这个问题? 我是JS的初学者,所以我一点头绪都没有。

【问题讨论】:

标签: javascript laravel datatable


【解决方案1】:

在数据表脚本上方添加 JQuery。它应该如下所示。

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>

不要忘记在里面添加数据表 CSS

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">

var table = $('#example').DataTable( {
    "processing": true,
    "serverSide": true,
     "ordering": true,
     "searching": true,
      "order": [1, 'asc'],
      "lengthMenu": [
                [10, 20, 50, 100],
                [10, 20, 50, 100]
            ],
    "pageLength": 10,
         

} );

希望对你有所帮助。

【讨论】:

  • 可悲的是,仍然卡住了。 T-T
猜你喜欢
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 2021-09-21
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
相关资源
最近更新 更多