Datatable Laravel 2.0

栏目: IT技术 · 发布时间: 4年前

内容简介:A simple package to ease datatable.js server side operationsThis package is created to handle

jQuery Datatables For Laravel 5.x

A simple package to ease datatable.js server side operations

This package is created to handle server-side and client-side works of DataTables jQuery Plugin via AJAX option by using Eloquent ORM, Query Builder or Collection.

datatable-laravel 2.0

Version 2.0 continues the improvements in version 1.0.3 by introducing some new functions , improved code structure and various bug fixes.

New

Introduced three new functions for the case if you know query is instance of which class. Currently supported include: Eloquent Query Builder, Database Query Builder and Eloquent Collection

  echo  datatable()->eloquent(User::query())->init();
  echo  datatable()->collection(User::query())->init();
  echo  datatable()->queryBuilder(User::query())->init();

Modified

Modified make and datatable function . Second parameter here is boolean with default to false indicate whether you want json response or not. If you don't pass second parameter then you need to use init() function as we are using in previous version.

echo datatable()->make(User::query(),true);
echo datatable(User::query(),true);

Using Helper Function

echo datatable()->of(User::query())->init();
echo datatable()->of(DB::table('users')->join1()->join2()->select(column1,column2,...columnK))->init();
echo datatable()->of(DB::table('users'))->init();
echo datatable()->of(User::all())->init();

echo datatables(User::query());
echo datatables(DB::table('users')->join1()->join2()->select(column1,column2,...columnK));
echo datatables(DB::table('users'));
echo datatables(User::all());

Using Facade

use Datatable;

echo Datatable::of(User::query())->init();
echo Datatable::of(DB::table('users')->join1()->join2()->select(column1,column2,...columnK))->init();
echo Datatable::of(DB::table('users'))->init();
echo Datatable::of(User::all())->init();

echo Datatable::make(User::query());
echo Datatable::make(DB::table('users')->join1()->join2()->select(column1,column2,...columnK));
echo Datatable::make(DB::table('users'));
echo Datatable::make(User::all());

Add/Edit Column

use Datatable;

echo Datatable::of(User::query())->add(columnName,function($user){
    return "<a href='' id='$user->id'>$user->name</a>";
})->init();

Using Helper Function

echo datatable()->of(User::query())->add(columnName,function($user){
    return "<a href='' id='$user->id'>$user->name</a>";
})->init();

Add/Edit Multiple Columns

use Datatable;

echo Datatable::of(User::query())->addColumns([columnName1=>function($user){
    return "<a href='' id='$user->id'>$user->name</a>";
},columnName2=>function($user){
    return "<a href='' id='$user->id'>$user->name</a>";
}...])->init();

Remove Column

use Datatable;

echo Datatable::of(User::query())->remove(columnName)->init();

Remove Multiple Columns

use Datatable;

echo Datatable::of(User::query())->remove([columnName1,columnName2,...])->init();

Requirements

Quick Installation

$ composer require iyogesharma/datatable-laravel:"~1.0"

Service Provider & Facade (Optional on Laravel 5.5)

Register provider and facade on your config/app.php file.

'providers' => [
    ...,
    YS\Datatable\DatatableServiceProvider::class,
]

'aliases' => [
    ...,
    'Datatable' => YS\Datatable\Facades\Datatable::class,
     "Table"=>YS\\Datatable\\Facades\\Table::class
]

load css files

before </body> tag add

{{table()->css()}}

load script files

before </body> tag add

{{table()->scripts()}}

load Dependencies (css/js)

before </body> tag add

{{table()->dependencies()}}

Initialize Basic DataTable

In HTMl file inside document .ready function write

    {{table()->basic()}}

Initialize Ajax DataTable

In HTMl file inside document .ready function write

    {{table()->ajax($url,$columns,$configs)}}

Example

      {{table()->dependencies()}}
<script>
        $(document).ready(function(){
                {{ table()->ajax('ddd/ddd',
                    [   'name',
                        'email',
                        'office'
                    ],[
                        'paging'=>'true',
                        'fixedheader'=>'true',
                        'buttons'=>['colvis','copy','csv','print'],
                        'order'=>[[0,'desc']],
                        'lengthMenu'=> [[ 10, 20, 30, 40, 50], [ 10, 20, 30, 40, 50]],
                    ]
                )}}
        })
    </script>

License

The MIT License (MIT). Please see License File for more information.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web开发敏捷之道

Web开发敏捷之道

Sam Ruby、Dave Thomas、David Heineme Hansson / 慕尼黑Isar工作组、骆古道 / 机械工业出版社 / 2012-3-15 / 59.00元

本书第1版曾荣获Jolt大奖“最佳技术图书”奖。在前3版的内容架构基础上,第4版增加了关于Rails中新特性和最佳实践的内容。本书从逐步创建一个真正的应用程序开始,然后介绍Rails的内置功能。全书分为3部分,第一部分介绍Rails的安装、应用程序验证、Rails框架的体系结构,以及Ruby语言的知识;第二部分用迭代方式创建应用程序,然后依据敏捷开发模式搭建测试案例,最终用Capistrano完成......一起来看看 《Web开发敏捷之道》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具