DataTablesの設定周り

スポンサーリンク

Laravel10環境でAdminLTEを使っているのですが、

DataTablesを利用したので覚がき

<table class="table table-striped projects text-nowrap" id="dataTable">
    <thead>
        <tr>
            <th>
                ID
            </th>
            <th>
                カテゴリ名
            </th>
            <th>
                備考
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach ($categories as $category)
            <tr>
                <td>
                    {{ $category->id }}
                </td>
                <td>
                    {{ $category->name }}
                </td>
                <td>
                    {{ $category->biko }}
                </td>
            </tr>
        @endforeach
    </tbody>
</table>
<script>
    $(function() {
        $('#dataTable').DataTable({
            // 件数切替機能 無効
            lengthChange: false,
            // 検索機能 無効
            searching: false,
            // 情報表示 無効
            info: false,
            // ページング機能 無効
            paging: false,
            // 状態を保存する機能をつける
            stateSave: true,
            // 処理中の表記
            processing: true,
            // ソート対象外カラムを設定
            columnDefs: [
                { "orderable": false, "targets": [1, 2] }
            ],
        });
    });
</script>

config/adiminlte.phpの”Datatables”をアクティブにしておく。

'plugins' => [
    'Datatables' => [
        'active' => true,
        'files' => [

コメント

タイトルとURLをコピーしました