Extend html with SearchPanes

Extend html with SearchPanes

cmpluscmplus Posts: 65Questions: 13Answers: 0

Hello everyone, due to the amount of data I have in the tables I had to change the method of loading the data into the tables, now I was able to quickly load large amounts of data in the tables but since I changed the way of doing it now I am having trouble with the searchPanes search panel. I'm using Yajra but I still don't quite understand what I have to do to see the values in the searchPanes boxes, they are currently empty, I was given a code but I still can't understand what I have to do to see the database values inside the searchPanes.

/**
 * Build the DataTable class.
 *
 * @param QueryBuilder $query Results from query() method.
 */
public function dataTable(QueryBuilder $query): EloquentDataTable
{

    return (new EloquentDataTable($query))->setRowId('id')
        ->searchPane(
            'tipo',
             [
                 [
                      'value' => 1, // This is the value given when selected
                      'label' => 'display value',
                      'total' => 5, // optional
                      'count' => 3 // optional
                 ],
                 [
                      'value' => 2, // This is the value given when selected
                      'label' => 'display value 2',
                      'total' => 6, // optional
                      'count' => 5 // optional
                 ],
             ],
            function (\Illuminate\Database\Eloquent\Builder $query, array $values) {
                // Here you need to specify what to filter when a given value is given
                return $query
                    ->whereIn(
                        'tipo',
                        $values);
            }
        );

}

In the guide that has been made available you can find this

Adding SearchPanes to the backend
The SearchPanes can be filled in the datatables declaration via the searchPane() method. The method takes the column for which the SearchPane is, as well as the options of the SearchPane. It also allows you to set custom processing for the options.

public function dataTable($query) : Yajra\DataTables\DataTableAbstract
{
    return datatables()
        ->eloquent($query)
        // Adding the SearchPane
        ->searchPane(
            /*
             * This is the column for which this SearchPane definition is for
             */
            'user_id',
 
            /*
             * Here we define the options for our SearchPane. This should be either a collection or an array with the
             * form:
             * [
             *     [
             *          'value' => 1,
             *          'label' => 'display value',
             *          'total' => 5, // optional
             *          'count' => 3 // optional
             *     ],
             *     [
             *          'value' => 2,
             *          'label' => 'display value 2',
             *          'total' => 6, // optional
             *          'count' => 5 // optional
             *     ],
             * ]
             */
            fn() => User::query()->select('id as value', 'name as label')->get(),
 
            /*
             * This is the filter that gets executed when the user selects one or more values on the SearchPane. The
             * values are always given in an array even if just one is selected
             */
            function (\Illuminate\Database\Eloquent\Builder $query, array $values) {
                return $query
                    ->whereIn(
                        'id',
                        $values);
            }
        );
}

But what should I put to see the database values in here? I tried to do this but the result is negative

    /**
     * Build the DataTable class.
     *
     * @param QueryBuilder $query Results from query() method.
     */
    public function dataTable(QueryBuilder $query): EloquentDataTable
    {

        return (new EloquentDataTable($query))->setRowId('id')
        ->searchPane(
            'id',
            [
                [
                    'value' => 'id',
                    'label' => 'id',
                ],
            ],
            fn() => Ticket::query()->select('id as value', 'id as label')->get(),
            'tipo',
            [
                [
                'value' => 'tipo',
                'label' => 'tipo',
                ], 
            ],
            fn() => Ticket::query()->select('tipo as value', 'tipo as label')->get(),
            function (\Illuminate\Database\Eloquent\Builder $query, array $values) {
                return $query
                    ->whereIn(
                        'id',
                        'tipo',
                        $values);
            }
        );

    }

Can anyone help me solve this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    When you say you changed the way you were loading data, do you mean you enabled server-side processing? If so, you would need to have a server-side script that supports server-side processing for SearchPanes.

    I don't know if the Yajra library does that or not I'm afraid. You'd need to refer to their documentation.

    Allan

  • cmpluscmplus Posts: 65Questions: 13Answers: 0

    After many attempts I managed to find a way to see the values but the problem is that they are not grouped and do not count for anything and this thing is not good. I still can't complete but can anyone tell me where is the error? i've been going crazy for weeks and now that i've managed to see the values are not displaying right, any ideas?

            return $this->builder()
                        ->setTableId('tickets-table')
                        ->columns($this->getColumns())
                        ->minifiedAjax()
                        ->orderBy(1)
                        ->selectStyleSingle()  
                        ->searchPanes(
                            SearchPane::make()
                                ->viewTotal(true)
                                ->viewCount(true)
                                ->clear(true)
                                ->controls(true)
                                ->layout('columns-4')
                                ->orderable(true)
                                ->collapse(true)
                        )
                        ->addColumnDef([
                            'searchPanes' => ['show' => true],
                            'targets' => [5, 9, 10, 12]
                        ])
    
    Column::make('priorita')->searchPanes(SearchPane::make()->modelOptions(Ticket::class, 'priorita')),
                Column::make('risorsa')->searchPanes(SearchPane::make()->modelOptions(Ticket::class, 'risorsa')),
                Column::make('categoria')->searchPanes(SearchPane::make()->modelOptions(Ticket::class, 'categoria')),
    

    09311bcb8195ea364342624cf4087c67.png

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    It looks like you have a question open with the Yarja Datatables developers. I don't believe there is any Yarja Datatables expertise on this forum. The best option is to continue working with the developers of Yarja Datatables.

    Kevin

  • cmpluscmplus Posts: 65Questions: 13Answers: 0

    @kthorngren
    yes you are right, i'm looking for a solution but i can't find it and i tried to write here too. but you are right i have to wait if they reply from the other side.

Sign In or Register to comment.