定制 arseto/laravel-table-view 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arseto/laravel-table-view

Composer 安装命令:

composer require arseto/laravel-table-view

包简介

Laravel 5 Package for easily displaying table views for Eloquent Collections with search and sort functionality built in.

README 文档

README

Laravel 5 Package for easily displaying table views for Eloquent Collections with search and sort functionality built in.

This is a fork to attempt continuation of the original project here.

Installation

Update your composer.json file to include this package as a dependency

"arseto/laravel-table-view": "dev-master"

Register the TableView service provider by adding it to the providers array in the config/app.php file.

'providers' => array(
    Arseto\LaravelTableView\LaravelTableViewServiceProvider::class
)

If you want you can alias the TableView facade by adding it to the aliases array in the config/app.php file.

'aliases' => array(
        'TableView' => Arseto\LaravelTableView\Facades\TableView::class,
)

Configuration

Copy the vendor file views and assets into your project by running

php artisan vendor:publish

This will add multiple styles and one script to public/vendor/table-view The plugin depends on jQuery and v1.9.1 will be included under public/vendor/table-view - Bootstrap CSS v3.3.2 - Font Awesome v4.3.0 - jQuery v1.9.1

Usage

Initialize the table view by passing in an instance of \Illuminate\Eloquent\Builder or simply the class name of the model for the tableview

	$users = User::select('id', 'name', 'email', 'created_at');

	$usersTableView = TableView::collection( $users )
	// or $usersTableView = TableView::collection( \App\User::class )

Adding Columns to the tableview

	$usersTableView = $usersTableView
		// you can pass in the title for the column, and the Eloquent\Model property name
		->column('Email', 'email')

		// Add a colon after the Eloquent\Model property name along with sort and/or search to enable these options
		->column('Name', 'name:sort,search')

		// Set the default sorting property with 
		->column('Name', 'name:sort*,search')	// Sorted Ascending by default or specify
		->column('Name', 'name:sort*:asc')
		->column('Name', 'name:sort*:desc')

		// Custom column values are created by passing an array with the Eloquent\Model property name as the key
		//  and a closure function
		->column('Joined At', ['created_at:sort*' => function ($user) 
		{
			return $user->created_at->diffForHumans();
		}])



		// OR
		->column(function ($user) 
		{
			return '<img src="' . $user->image_path . '" height="60" width="60">';
		})
		->column('Email', 'email:sort,search')
		->column(function ($user) 
		{
			return '<a class="btn btn-success" href="/users/' . $user->id . '">View</a>';
		});

Custom column values

	$usersTableView = $usersTableView
		// You can pass in an array for the column's row value with the Eloquent\Model property name as the key
		//  and a closure function
		->column('Joined At', ['created_at:sort*' => function ($user) 
		{
			return $user->created_at->diffForHumans();
		}])

		// OR if sorting and searching is unnecessary, simply pass in the Closure instead of the array
		->column('Image', function ($user) 
		{
			return '<img src="' . $user->image_path . '" height="60" width="60">';
		});
}]);

Columns without titles

	$usersTableView = $usersTableView
		// Just leave the column title out if you don't want to use it
		->column(function ($user) 
		{
			return '<img src="' . $user->image_path . '" height="60" width="60">';
		});

Additional Controls - you can add partial views containing custom controls like a filter button to add additional functionality to your table

	$usersTableView = $usersTableView
		// Just pass in the partial view file path of the custom control
		->headerControl('_types_filter_button');

		// access the TableView data collection with $usersTableView->data()

Finally, build the TableView and pass it to the view

	$usersTableView = $usersTableView->build();

	return view('test', [
		'usersTableView' => $usersTableView
	]);

All together with chaining

Route::get('/', function(\Illuminate\Http\Request $request) 
{
	$users = User::select('id', 'name', 'email', 'created_at');

	$usersTableView = TableView::collection( $users, 'Administrator' )
		->column(function ($user) 
		{
			return '<img src="' . $user->image_path . '" height="60" width="60">';
		})
		->column('Name', 'name:sort,search')
		->column('Email', 'email:sort,search')
		->column('Joined At', ['created_at:sort*' => function ($user) 
		{
			return $user->created_at->diffForHumans();
		}])
		->column(function ($user) 
		{
			return '<a class="btn btn-success" href="/users/' . $user->id . '">View</a>';
		})
		->headerControl('_types_filter_button')
		->build();

	return view('test', [
		'usersTableView' => $usersTableView
	]);
});

Front End

Include stylesheets for Bootstrap and Font Awesome - Bootstrap CSS v3.3.2 and Font Awesome v4.3.0 are included in the vendor

<link href="{{ asset('vendor/table-view/bootstrap.min.css') }}" rel="stylesheet" />
<link href="{{ asset('vendor/table-view/font-awesome/css/font-awesome.min.css') }}" rel="stylesheet" />
<link href="{{ asset('vendor/table-view/css/themes/tableview-a.css') }}" rel="stylesheet" />

Include the tablview in your view, referencing the variable name given to it

@include('table-view::container', ['tableView' => $usersTableView])

Also include the tablview scripts ** Requires jQuery and v1.9.1 will be included under public/vendor/table-view

<script src="{{ asset('vendor/table-view/js/jquery-1.9.1.min.js') }}"></script>

@include('table-view::scripts')

Middleware Cookie Storage

Selected options for the tableview are easily added to cookie storage with built-in Middleware.

Sort options and limits per page are each added to permanent storage. At any point, a user returning to the tableview will see these options filled with the same values that he/she selected in his/her most recent session.

The search query and page number are temporarily stored during the user's current session. With this, a user could visit something http://tableview.com/blog-articles with the tableview listing articles. When a user views a specific article like http://tableview.com/blog-articles/laravel-blog/article, any link back to http://tableview.com/blog-articles will show the tableview with its most recent page number and search query.

All you have to do:

Edit app/Http/Kernel.php, adding a reference to the Middleware

    /**
     * The application's route middleware.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,

        // Laravel TableView Middleware
        'table-view.storage' => \Arseto\LaravelTableView\Middleware\TableViewCookieStorage::class,
    ];

Then add it to the route containing the tableview

    Route::get('/', ['middleware' => 'table-view.storage', function () {

That's it!

It's particular but in just a few lines you have a dynamic table view with powerful functionality. Feel free to customize the tableview and element partial views. Additional themes and styles coming soon.

arseto/laravel-table-view 适用场景与选型建议

arseto/laravel-table-view 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「search」 「pagination」 「sort」 「laravel」 「laravel 5」 「data table」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 arseto/laravel-table-view 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arseto/laravel-table-view 我们能提供哪些服务?
定制开发 / 二次开发

基于 arseto/laravel-table-view 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-12