在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bgultekin/laravel4-datatables-package开源软件地址(OpenSource Url):https://github.com/bgultekin/laravel4-datatables-package开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Project is not being maintained actively.You will most likely find a better more actively maintained fork here https://github.com/yajra/laravel-datatables If you have issues please try and fix them and we will pull the changes if we can verify they work. That being said this project lacks automatic testing so it has become a difficult project to maintain. Please let us know if you are interested in adopting and maintaining this project, it is still pretty useful. 60% of the time, it works every time. Datatables Bundle for Laravel 4About This bundle is created to handle the server-side processing of the DataTables Jquery Plugin (http://datatables.net) by using Eloquent ORM or Fluent Query Builder. Feature Overview
InstallationRequire
Composer will download the package. After the package is downloaded, open
Finally you need to publish a configuration file by running the following Artisan command. $ php artisan config:publish bllim/datatables UsageIt is very simple to use this bundle. Just create your own fluent query object or eloquent object without getting results (that means don't use get(), all() or similar methods) and give it to Datatables. You are free to use all Eloquent ORM and Fluent Query Builder features. Some things you should know:
ExamplesExample 1: Simple use
Example 2: Adding and editing columns
Notice: If you use double quotes while assigning the $content in an
Example 3: Using filter_column
Notes on filter_column: Usage:
Example 4: Returning an array of objects
This returns a JSON array with data like below:
Example 5: DT_RowID, DT_RowClass and DT_RowData $todo = ToDoList::select(array('todo.id','todo.name','todo.created_at','todo.status'));
return Datatables::of($todo)
->set_index_column('id')
->set_row_class('@if($status=="done") success @endif')
->set_row_data('created_at','{{$created_at}}')
->make(); Example 6: Advanced usage of dataFullSupport To better utilize dataTables mData (1.9), now columns.data (1.10) feature you may enable dataFullSupport by either setting it to true in the config file, or passing true to the second initialization argument Creating a table with a searchable and sortable joined table: //html
<table id="user-list"></table>
//script.js
$("#users-list").dataTable({
"processing": true,
"serverSide": true,
"ajax": "/api/user/datatables",
"order": [[1,'desc']],
"columnDefs": [ { //this prevents errors if the data is null
"targets": "_all",
"defaultContent": ""
} ],
"columns": [
//title will auto-generate th columns
{ "data" : "id", "title" : "Id", "orderable": true, "searchable": false },
{ "data" : "profile.last_name","title" : "Name", "orderable": true, "searchable": true },
{ "data" : "username", "title" : "Username", "orderable": true, "searchable": true },
{ "data" : "email", "title" : "Email", "orderable": true, "searchable": true },
{ "data" : "created_date", "title" : "Created", "orderable": true, "searchable": true },
]
}); $users = Models\User::select()->ModelJoin('profile');
return $dataTables = Datatables::of($users)
->filter_column('profile.last_name','where',\DB::raw('CONCAT(profile.last_name,\' \',profile.first_name)'),'LIKE','$1')
->filter_column('created_at','where','users.created_at','LIKE','$1')
//for the blade template only the array data results is provided, it is `extracted` into the template
->edit_column('profile.last_name', '{{ $profile["first_name"]." ".$profile["last_name"] }}')
->edit_column('created_at', function($result_obj) {
//in a callback, the Eloquent object is returned so carbon may be used
return $result_obj->created_at->format('d/m/Y - h:ia');
})
->add_column('manage', '<a href="/user/edit/{{$id}}" >Edit</a>', 3)
->remove_column('profile.photo_id')
->set_index_column('row-{{ $id }}')
->make(); //helper scope method in base Model class
public function scopeModelJoin($query, $relation_name, $operator = '=', $type = 'left', $where = false) {
$relation = $this->$relation_name();
$table = $relation->getRelated()->getTable();
$one = $relation->getQualifiedParentKeyName();
$two = $relation->getForeignKey();
if (empty($query->columns)) {
$query->select($this->getTable().".*");
}
//$join_alias = $table;
$prefix = $query->getQuery()->getGrammar()->getTablePrefix();
$join_alias = $relation_name;
foreach (\Schema::getColumnListing($table) as $related_column) {
$query->addSelect(\DB::raw("`$prefix$join_alias`.`$related_column` AS `$join_alias.$related_column`"));
}
$two = str_replace($table . ".", $join_alias . ".", $two);
return $query->join("$table AS $prefix$relation_name", $one, $operator, $two, $type, $where); //->with($relation_name);
} Notes on columns.data:
License: Licensed under the MIT License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论