yajra / laravel-datatables-docs Goto Github PK
View Code? Open in Web Editor NEWLaravel DaTatables package documentation
Home Page: https://yajrabox.com/docs/laravel-datatables
Laravel DaTatables package documentation
Home Page: https://yajrabox.com/docs/laravel-datatables
In the below method I want to return joined tables data. is there any documentation to refere please
public function query(User $model): QueryBuilder
{
return $model->newQuery();
}
The example of the joint
$users = DB::table('users')
->join('businesses', 'users.business_id', '=', 'businesses.id')
->select('users.id','users.name', 'users.email', 'businesses.company_name as business')
->get();
return $users->newQuery();
I bought the editor, but if I follow your guide, when I insert the editor buttons everything disappears, it doesn't work and I don't understand why, I'm using laravel 10 and I followed all the guide described here but when I put the editor I can't see anything anymore
it stays loading and you don't see any buttons
Update Editor Events code samples to describe changes on version 1.8.0 of laravel-datatables-editor.
before upgraded to 10.0, the float / integer number can be searched.
public function dataTable(QueryBuilder $query, Request $request): EloquentDataTable
{
return (new EloquentDataTable($query))
->addColumn('title',fn($query) => "$query->makeTitle $query->makeModelTitle $query->year")
->addColumn('body type',fn($query) => $query->bodyTypeTitle)
->addColumn('price', fn($query) => $query->price)
->addColumn('image', function($query) {
$image = asset($query->getFirstMediaUrl('featured_image'));
return '<img src="'.$image.'" alt="user-image" class="rounded-circle"
style="height: 50px;width: 50px;object-fit: cover;">';
})
->addColumn('active',function($query){
$checked = $query->is_active ? "checked" : "";
$switcherRoute = route('cars.toggle',$query->id);
$csrfToken = csrf_token();
$switcher = '
<form action="'.$switcherRoute. '" method="post">
<label class="switch">
<input type="hidden" name="_token" value="'.$csrfToken.'">
<input type="hidden" name="_method" value="PATCH">
<input type="checkbox" id="carActivation'.$query->id.'" class="switch-input" '. $checked .' data-car-id="'.$query->id. '" onclick="carActivation(this,'.$query->id.',this.checked)"/>
<span class="switch-toggle-slider">
<span class="switch-on">
<i class="bx bx-check"></i>
</span>
<span class="switch-off">
<i class="bx bx-x"></i>
</span>
</span>
<span class="switch-label">Active</span>
</label>
</form>
';
return $switcher;
})
->addColumn('created',fn($query) => date('Y-m-d', strtotime($query->created_at)))
->addColumn('bookings',fn($query) => $query->booking_count)
->addColumn('actions',function($query){
$showRoute = route("cars.show", $query->id);
$show = '<button class="btn btn-sm btn-icon show-record">
<a href="'.$showRoute.'">
<i class="fa fa-eye"></i>
</a>
</button>';
$editRoute = route('cars.edit', $query->id);
$edit = '<button class="btn btn-sm btn-icon edit-record">
<a href="'.$editRoute.'">
<i class="fa fa-edit"></i>
</a>
</button>';
$delete = '<button class="btn btn-sm btn-icon delete-record" type="submit" style="color: #5a8dee" data-bs-toggle="modal" data-bs-target="#enableOTPCar'. $query->id.'">
<i class="fa fa-trash"></i>
</button>';
$deleteRoute = route('cars.destroy',$query->id);
$include = view('_partials.deleteModal',[
'id' => 'Car'.$query->id,
'title' => 'Delete car',
'msg' => "Are you sure about deleting {$query->make->title} {$query->makeModel->title} {$query->year}",
'form_action' => $deleteRoute
]);
return $show . $edit . $delete . $include;
})
->rawColumns(['image','actions','active'])
->filterColumn('bookings', function($query, $keyword) {
$keywords = trim($keyword);
$query->havingRaw("COUNT(bookings.id) AS booking_count = ?", ["{$keywords}"]);
})
->orderColumn('title', function ($query, $order) {
$query->orderBy('makeTitle', $order);
})
->orderColumn('body type', function ($query, $order) {
$query->orderBy('bodyTypeTitle', $order);
})
->orderColumn('price', function ($query, $order) {
$query->orderBy('price', $order);
})
->filter(
fn ($query) =>
$query->when(
$request->search['value'] ?? false, fn($query) =>
$query->where('year', 'like', '%' . $request->search['value'] . '%')
->orWhere('price', 'like', '%' . $request->search['value'] . '%')
->orWhere('cars.created_at', 'like', '%' . $request->search['value'] . '%')
// Relations
->orWhereHas('make', fn ($query) =>
$query->where('title', 'like', '%' . $request->search['value'] . '%')
)
->orWhereHas('makeModel', fn ($query) =>
$query->where('title', 'like', '%' . $request->search['value'] . '%')
)
->orWhereHas('bodyType', fn ($query) =>
$query->where('title', 'like', '%' . $request->search['value'] . '%')
)
)
)
->setRowId('id');
}
public function query(Car $model): QueryBuilder
{
$selectColumns = [
'cars.id',
'makes.title as makeTitle',
'body_types.title as bodyTypeTitle',
'price_packages.price as price',
'cars.make_id',
'cars.is_active',
DB::raw('COUNT(bookings.id) AS booking_count'),
'cars.created_at',
'make_models.title as makeModelTitle',
'cars.make_model_id',
'cars.body_type_id',
'cars.price_plan_id',
];
$query = $model->select($selectColumns)->join('makes','makes.id','=','cars.make_id')
->join('make_models','make_models.id','=','cars.make_model_id')
->join('body_types','body_types.id','=','cars.body_type_id')
->join('price_plans','price_plans.id','=','cars.price_plan_id')
->join('bookings','bookings.car_id','=','cars.make_model_id')
->leftJoin('price_packages',fn($join) =>
$join->on('price_packages.price_plan_id','=','price_plans.id')
->where('price_packages.title','default')
)
->groupBy('cars.id', 'makes.title', 'body_types.title', 'price_packages.price', 'cars.make_id', 'cars.is_active', 'cars.created_at', 'make_models.title', 'cars.make_model_id', 'cars.body_type_id', 'cars.price_plan_id');
if(auth()->user()->hasRole('shop')){
$query->where('cars.shop_id',auth()->user()->shop_id);
}
// dd($query->toSql());
return $query;
}
Help to get out of this issue.
I'm using individual column search, the filter column is not working with DB::raw.
These are the versions
"yajra/laravel-datatables": "9.0",
"yajra/laravel-datatables-oracle": "^10.0"
Website https://yajrabox.com/docs/laravel-datatables is offline
Look this code
public function plex_cliente_datatables() {
$clientes = PlexCliente::query();
return DataTables::eloquent($clientes->with('servicos_alias'))
->addColumn('servicos_alias', function(PlexCliente $c) {
$servicos = null;
foreach($c->servicos_alias as $servico) {
$servicos .= $servico->id . ($servico->alias ? '(' . $servico->alias . ')' : ''). ', ';
}
return substr($servicos, 0, -2);
})
->filterColumn('cpf_cnpj', function($query, $keyword) {
$sql = "REPLACE(REPLACE(REPLACE(cpf_cnpj, '.', ''), '-', ''), '/', '') LIKE ?";
$keyword = preg_replace('/\D/', '', $keyword);
$query->whereRaw($sql, ["%{$keyword}%"]);
})
->toJson();
}
When I use the filterColumn, the search works only for this column.
Can you help how to fix this?
https://yajrabox.com/docs/laravel-datatables/9.0/installation
Service Implementation item leads to a 404 : https://datatables.yajrabox.com/service
where is old documention of Yajra Laravel DataTables..where all example is available with source code??
Hello, I got the error when trying to return more than 10k+ of records. Error: "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted". Is there any solution for this instead of changing the "memory_limit" in php.ini?
'options' => [
'searching' => true,
'paging' => true,
'info' => false,
'language' => [
'sSearch' => '',
'searchPlaceholder' => 'Search',
'info' => 'START - END of TOTAL',
'sLengthMenu' => 'View MENU',
'paginate' => [
'next' => '',
'previous' => '',
],
],
],
config/datatable.php may i define in config file but is not work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.