laravel-datatables icon indicating copy to clipboard operation
laravel-datatables copied to clipboard

[Feature] Add support SearchBuilder

Open vanthao03596 opened this issue 3 years ago β€’ 26 comments

SearchBuilder is new extension and really good. Can we add support this ?

vanthao03596 avatar Jun 13 '21 15:06 vanthao03596

Search builder extension only works on client-side. Will consider this once the serverSide implementation is available.

yajra avatar Jun 20 '21 08:06 yajra

hey @yajra SearchBuilder support server-side processing in version 1.2

vanthao03596 avatar Aug 28 '21 04:08 vanthao03596

@vanthao03596 Can you please provide some links for reference?

yajra avatar Aug 28 '21 04:08 yajra

Here https://editor.datatables.net/examples/extensions/searchBuilderTypes.html

vanthao03596 avatar Aug 28 '21 11:08 vanthao03596

+1

hamzaFpco avatar Sep 13 '21 14:09 hamzaFpco

@yajra @hamzaFpco i made a gist with simple scope for SearchBuilder base on datatable. Hope it can help https://gist.github.com/vanthao03596/b49747bf5725a97d091f482d42c7c576

vanthao03596 avatar Sep 15 '21 08:09 vanthao03596

@yajra @hamzaFpco i made a gist with simple scope for SearchBuilder base on datatable. Hope it can help https://gist.github.com/vanthao03596/b49747bf5725a97d091f482d42c7c576

hi, how to use this script?

armadeas avatar Dec 02 '21 08:12 armadeas

@yajra @hamzaFpco i made a gist with simple scope for SearchBuilder base on datatable. Hope it can help https://gist.github.com/vanthao03596/b49747bf5725a97d091f482d42c7c576

hi, how to use this script?

Use this trait in your model

vanthao03596 avatar Dec 02 '21 08:12 vanthao03596

thanks for sharing. I use DataTableScope

https://gist.github.com/armadeas/61d0ed9e846c3ede8afa3fc6cdc18a97

armadeas avatar Dec 02 '21 14:12 armadeas

@yajra @hamzaFpco i made a gist with simple scope for SearchBuilder base on datatable. Hope it can help https://gist.github.com/vanthao03596/b49747bf5725a97d091f482d42c7c576

Thank you very much. This is very good πŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ‘πŸ‘β€

enaeim avatar Jan 04 '22 07:01 enaeim

thanks for sharing. I use DataTableScope

https://gist.github.com/armadeas/61d0ed9e846c3ede8afa3fc6cdc18a97

Hi. Thanks a lot. Why did you use the $columns parameter in the searchBuilderCondition method?

protected function searchBuilderCondition($query, $data, $columns)
{
    // . . .
}

enaeim avatar Jan 04 '22 07:01 enaeim

yes because I use relationships from several tables, so that the searchbuilder can work specifically on which columns from the table to filter

armadeas avatar Jan 04 '22 08:01 armadeas

thanks for sharing. I use DataTableScope

https://gist.github.com/armadeas/61d0ed9e846c3ede8afa3fc6cdc18a97

Thank you for your answer. I had another question. The following class is not defined in the scope you wrote. Where is this class?

use Yajra\DataTables\Contracts\DataTableScope;

class SearchBuilderScope implements DataTableScope
{
    // . . .
}

image image

enaeim avatar Jan 04 '22 08:01 enaeim

sorry if it's messy. Initially I made a scope like the following link https://datatables.yajrabox.com/services/scope This scope is included in the service button https://yajrabox.com/docs/laravel-datatables/master/buttons-installation

after that the contents are https://gist.github.com/armadeas/61d0ed9e846c3ede8afa3fc6cdc18a97 image

armadeas avatar Jan 04 '22 09:01 armadeas

Hello dear friends. @yajra @armadeas @vanthao03596 Another question. Sorry. How to add a relationship field to searchbuilder. For example, in my project, in the admin panel, there is a table containing all the admins of the site and there is no column as the their roles. But I want to search and find users who are operators in searchbuilder. How do I implement this using searchbuilder and yajra? I am new to datatables, yajra and jquery. I would be very grateful if you could guide me or introduce me to the tutorial link or in-depth tutorial on this. Thanks a lot.

enaeim avatar Jan 05 '22 12:01 enaeim

Can anyone provide a working sample code? I did the whole process above but it still returns the error Class "App\DataTables\Scopes\SearchBuilderScope" not found I think I have a problem calling the scope in the Model

humbertleonardo avatar Nov 29 '22 08:11 humbertleonardo

@vanthao03596 '!contains' case block is missing.

radz2k avatar Jan 13 '23 08:01 radz2k

Can anyone provide a working sample code? I did the whole process above but it still returns the error Class "App\DataTables\Scopes\SearchBuilderScope" not found I think I have a problem calling the scope in the Model

Please take a look i managed to make it work

  1. run this php artisan datatables:scope SearchBuilder
  2. Now add all that code mentioned in the gist to the SearchBuilder class Screenshot 2023-01-17 234942
  3. Then add that scope to your controller method
<?php

namespace App\Http\Controllers;

use App\DataTables\UsersDataTable;
use App\DataTables\Scopes\SearchBuilder;
use App\Helpers\Helper;

class UsersController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function list(UsersDataTable $dataTable)
    {
        $pageData = [
          'who_am_i'  => ' I AM Awsom'
        ];
        return $dataTable->addScope(new SearchBuilder)->render('pages.users.index',$pageData);
    }
} 
  1. Set your js and css accordingly..I am using metronic 8 theme so in my config it look like this Screenshot 2023-01-21 191823 That's all....

Followings are the things which make me stuck all day to make it all work

  1. In your datatable class to show search builder you need to add 'Q' to your dom, if you are using that like this Screenshot 2023-01-17 235314 Screenshot 2023-01-17 235433
  2. You might face "414 request-uri too large", i am using nginx ec2 instance so in my case i had to configure in the root of my nginx file nano /etc/nginx/nginx.conf like this
http {

        ##
        # Basic Settings
        ##
        client_header_buffer_size 64k; // this
        large_client_header_buffers 4 64k; // and this one

I hope it helps someone.

vipertecpro avatar Jan 17 '23 18:01 vipertecpro

Can anyone provide a working sample code? I did the whole process above but it still returns the error Class "App\DataTables\Scopes\SearchBuilderScope" not found I think I have a problem calling the scope in the Model

Please take a look i managed to make it work

  1. run this php artisan datatables:scope SearchBuilder
  2. Now add all that code mentioned in the gist to the SearchBuilder class Screenshot 2023-01-17 234942
  3. Then add that scope to your controller method
<?php

namespace App\Http\Controllers;

use App\DataTables\UsersDataTable;
use App\DataTables\Scopes\SearchBuilder;
use App\Helpers\Helper;

class UsersController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function list(UsersDataTable $dataTable)
    {
        $pageData = [
          'who_am_i'  => ' I AM Awsom'
        ];
        return $dataTable->addScope(new SearchBuilder)->render('pages.users.index',$pageData);
    }
} 
  1. Set your js and css accordingly..I am using metronic 8 theme so in my config it look like this Screenshot 2023-01-21 191823 That's all....

Followings are the things which make me stuck all day to make it all work

  1. In your datatable class to show search builder you need to add 'Q' to your dom, if you are using that like this Screenshot 2023-01-17 235314 Screenshot 2023-01-17 235433
  2. You might face "414 request-uri too large", i am using nginx ec2 instance so in my case i had to configure in the root of my nginx file nano /etc/nginx/nginx.conf like this
http {

        ##
        # Basic Settings
        ##
        client_header_buffer_size 64k; // this
        large_client_header_buffers 4 64k; // and this one

I hope it helps someone.

Hi, I am trying to config SearchBuilder server-side into may Laravel app and I am facing a lot of troubles. Could you please help me ? Maybe a tutorial about how I can make it work.....

Yuri-M1 avatar Mar 08 '23 17:03 Yuri-M1

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful.

https://medium.com/@saaifulislam/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

saaiful avatar Apr 16 '23 14:04 saaiful

Hi Saiful,

Thank you for your e-mail.

Best Regards,

Yuri

De: Saiful Islam @.> Enviada em: domingo, 16 de abril de 2023 11:47 Para: yajra/laravel-datatables @.> Cc: Yuri Araujo @.>; Comment @.> Assunto: Re: [yajra/laravel-datatables] [Feature] Add support SearchBuilder (#2648)

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful.

@.***/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

β€” Reply to this email directly, view it on GitHubhttps://github.com/yajra/laravel-datatables/issues/2648#issuecomment-1510403875, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A25KZZJCZWU2O4A3DRHRINTXBQA5JANCNFSM46T2TNTQ. You are receiving this because you commented.Message ID: @.@.>>

Yuri-M1 avatar Apr 16 '23 14:04 Yuri-M1

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful.

https://medium.com/@saaifulislam/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

Yes that's perfect keep updating that....

vipertecpro avatar Apr 18 '23 03:04 vipertecpro

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful.

https://medium.com/@saaifulislam/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

@saaiful Is it possible to get this working with model attributes set using accessors, the columns wouldn't exist in the DB so I obviously get an error from SQL.

I would like to be able to filter based on these fields using Search Builder.

ale1981 avatar Dec 12 '23 17:12 ale1981

Hi,

Thank you for your e-mail. I will try it.

Best Regards

Yuri

De: ale1981 @.> Enviada em: terça-feira, 12 de dezembro de 2023 14:43 Para: yajra/laravel-datatables @.> Cc: Yuri Araujo @.>; Comment @.> Assunto: Re: [yajra/laravel-datatables] [Feature] Add support SearchBuilder (#2648)

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful.

@.***/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

@saaifulhttps://github.com/saaiful Is it possible to get this working with model attributes set using accessors, the columns wouldn't exist in the DB so I obviously get an error from SQL.

I would like to be able to filter based on these fields using Search Builder.

β€” Reply to this email directly, view it on GitHubhttps://github.com/yajra/laravel-datatables/issues/2648#issuecomment-1852515599, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A25KZZOVRV6LIHKN73IRRCTYJCJRZAVCNFSM46T2TNT2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVGI2TCNJVHE4Q. You are receiving this because you commented.Message ID: @.@.>>

Yuri-M1 avatar Dec 12 '23 22:12 Yuri-M1

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful. https://medium.com/@saaifulislam/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

@saaiful Is it possible to get this working with model attributes set using accessors, the columns wouldn't exist in the DB so I obviously get an error from SQL.

I would like to be able to filter based on these fields using Search Builder.

You cannot filter data directly based on an accessor when using Yajra DataTables with the Eloquent driver in Laravel. Accessors are used to modify or format data when it's retrieved from the database, but they are not used for filtering or querying data.

saaiful avatar Dec 13 '23 13:12 saaiful

If you want to use SearchBuilder with a server-side implementation, you may find this article helpful. https://medium.com/@saaifulislam/implementing-searchbuilder-with-yajra-datatables-in-laravel-a-step-by-step-guide-39314791ac5b

@saaiful Is it possible to get this working with model attributes set using accessors, the columns wouldn't exist in the DB so I obviously get an error from SQL. I would like to be able to filter based on these fields using Search Builder.

You cannot filter data directly based on an accessor when using Yajra DataTables with the Eloquent driver in Laravel. Accessors are used to modify or format data when it's retrieved from the database, but they are not used for filtering or querying data.

U can try use whereHas with the filter without any modification, of course, is a whereHas by every related model:

Captura de pantalla 2024-01-10 a las 13 30 04

$model = \App\students ->whereHas("students.status",function($query) use ($r){ // the current model$sb = new SearchBuilder($r, $query, ["students.status.name"], ["students.status.name" => "name"]); // let pass relation columns, students.status.name not exists yet, then use the column name using replacement array $query = $sb->build(); // return the new build query }) ->with("students.status.name") // optional if u want to retry relation info too

david-valdivia avatar Jan 10 '24 19:01 david-valdivia