cuongnd88/lara-simple-datatable
Composer 安装命令:
composer require cuongnd88/lara-simple-datatable
包简介
Laravel Simple Datatable enhances the accessibility of data in HTML tables
README 文档
README
Laravel Simple Datatable enhances the accessibility of data in HTML tables
https://github.com/cuongnd88/lara-simple-datatable
1-Install cuongnd88/lara-simple-datatable using Composer.
$ composer require cuongnd88/lara-simple-datatable
2-Add the following service provider in config/app.php
<?php // config/app.php return [ // ... 'aliases' => [ . . . . 'SimpleDatatable' => Cuongnd88\LaraSimpleDatatable\Facades\SimpleDatatableFacade::class, ], // ... ];
You can modify the Simple Datatable interface by copying its components to your local config directory:
php artisan vendor:publish --provider="Cuongnd88\LaraSimpleDatatable\LaraSimpleDatatableServiceProvider"
Sample Usage
Let start code less with Laravel Simple Datatable
.... use SimpleDatatable; class UserController extends Controller { public function index(Request $request) { $users = SimpleDatatable::buildQuery(User::query()) ->setPerPage(10) ->addIncrement(function($value) { return "#{$value["increment"]}"; }) ->editColumn('id', function($value) { return "[{$value["id"]}]"; }) ->editColumn('name', 'user.partials.name') ->addColumn('action', 'user.partials.action') ->make(); return view('user.index', ['users' => $users]); } }
buildQuery(Builder $query): set Query build.
setPerPage(int $perPage) is to set quantity of items per page.
addIncrement($callback) is to add increment number.
editColumn(string $key, $callback|$view) is to edit existed column.
addColumn(string $key, $callback|$view) is to add mroe column.
make() is to make simple datatable.
Simple Datatable makes your job more easier to render view by using @simpleDatatable and @simplePaginator
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Simple Datatable</div>
<div class="card-body">
@simpleDatatable(['data' => $users, 'view' => simple_table_view('users')])
@endsimpleDatatable
@simplePaginator(['data' => $users, 'appends' => ['name' => 'cuong.ngo']])
@endsimplePaginator
</div>
</div>
</div>
</div>
</div>
@endsection
@simpleDatatable(array $result): $result must has key data for content and key view for setting views.
@simplePaginator(array $result): $result must has key data for content and key appends is optional for your extend data (ex: http://localhost:8080/users?name=cuong.ngo&page=10).
simple_table_view(string $view): is to set table headers which is loaded from simple-datatable.php in config folder .
<?php return [ /* |-------------------------------------------------------------------------- | Default paginator view |-------------------------------------------------------------------------- | */ 'paginator_view' => 'components.simple-datatable.default-bootstrap-4', /* |-------------------------------------------------------------------------- | Default simple paginator view |-------------------------------------------------------------------------- | */ 'simple_paginator_view' => 'components.simple-datatable.default-bootstrap-4', /* |-------------------------------------------------------------------------- | Default makeup for simple table view |-------------------------------------------------------------------------- | */ 'default_table_makeup' => 'table-striped table-hover', /* |-------------------------------------------------------------------------- | Setting views for specified datatable |-------------------------------------------------------------------------- | */ 'views' => [ 'users' => [ 'items' => [ 'increment' => '#', 'id' => 'ID', 'name' => 'Name', 'email' => 'Email', 'action' => '', ], ], ], ];
- To modify the view of column, you can create blade file as
addColumn('action', 'user.partials.action')
<a href="user/{{$id}}">Edit</a> | <a href="user/{{$id}}/remove">Remove</a>
- You also modify the view of whole table, you can see at simple-datatable.blade.php
@php $makeup = $view['makeup'] ?? ''; $keys = array_keys($view['items']); $headLabels = array_values($view['items']); @endphp <table class="table {{$makeup}}"> <thead> <tr> @foreach ($headLabels as $label) <th scope="col">{{$label}}</th> @endforeach </tr> </thead> <tbody> @foreach ($data as $item) <tr> @foreach ($keys as $key) <td>{{ $item[$key] ?? '' }}</td> @endforeach </tr> @endforeach </tbody> </table>
cuongnd88/lara-simple-datatable 适用场景与选型建议
cuongnd88/lara-simple-datatable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 543 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「paginator」 「pagination」 「laravel」 「datatable」 「paginate」 「simple datatable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cuongnd88/lara-simple-datatable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cuongnd88/lara-simple-datatable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cuongnd88/lara-simple-datatable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony DataGridBundle
MongoDB Adapter to be used with Laminas Paginator
Provides a Data Grid tables for your Symfony project.
ThinkPHP6分页驱动
Normalize an index range from user input
Display page number links in Twig or PHP templates.
统计信息
- 总下载量: 543
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-26