Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support SearchBuilder #2648

Open
vanthao03596 opened this issue Jun 13, 2021 · 26 comments
Open

[Feature] Add support SearchBuilder #2648

vanthao03596 opened this issue Jun 13, 2021 · 26 comments

Comments

@vanthao03596
Copy link

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

@yajra
Copy link
Owner

yajra commented Jun 20, 2021

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

@vanthao03596
Copy link
Author

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

@yajra
Copy link
Owner

yajra commented Aug 28, 2021

@vanthao03596 Can you please provide some links for reference?

@vanthao03596
Copy link
Author

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

@hamzaFpco
Copy link

+1

@vanthao03596
Copy link
Author

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

@armadeas
Copy link

armadeas commented Dec 2, 2021

@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?

@vanthao03596
Copy link
Author

@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

@armadeas
Copy link

armadeas commented Dec 2, 2021

thanks for sharing.
I use DataTableScope

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

@enaeim
Copy link

enaeim commented Jan 4, 2022

@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
Copy link

enaeim commented Jan 4, 2022

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)
{
    // . . .
}

@armadeas
Copy link

armadeas commented Jan 4, 2022

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

@enaeim
Copy link

enaeim commented Jan 4, 2022

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

@armadeas
Copy link

armadeas commented Jan 4, 2022

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

@enaeim
Copy link

enaeim commented Jan 5, 2022

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.

@humbertleonardo
Copy link

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

@radz2k
Copy link

radz2k commented Jan 13, 2023

@vanthao03596 '!contains' case block is missing.

@vipertecpro
Copy link

vipertecpro commented Jan 17, 2023

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.

@Yuri-M1
Copy link

Yuri-M1 commented Mar 8, 2023

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.....

@saaiful
Copy link

saaiful commented Apr 16, 2023

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

@Yuri-M1
Copy link

Yuri-M1 commented Apr 16, 2023 via email

@vipertecpro
Copy link

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....

@ale1981
Copy link

ale1981 commented Dec 12, 2023

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.

@Yuri-M1
Copy link

Yuri-M1 commented Dec 12, 2023 via email

@saaiful
Copy link

saaiful commented Dec 13, 2023

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.

@david-valdivia
Copy link

david-valdivia commented Jan 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests