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

Sorting relationships on table #45

Open
SigalZ opened this issue Dec 29, 2021 · 2 comments
Open

Sorting relationships on table #45

SigalZ opened this issue Dec 29, 2021 · 2 comments

Comments

@SigalZ
Copy link

SigalZ commented Dec 29, 2021

Hello,

Thank you for this package.

I do have some issues though.

I have these tables: coffees, roast_types, green_beans.

In the Coffee model I have these relationships:

public function roast_type()
    {
        return $this->belongsTo(RoastType::class);
    }

     public function green_bean()
    {
        return $this->belongsTo(GreenBean::class);
    }

In the CoffeeTable component I have this query:

return Coffee::with('roast_type')
        ->with('green_bean')
            ->where('coffees.active', $this->active)
            ->where('blend', 0);

and these columns:

return [
            Column::make('ID')->searchable()->sortable(),
            Column::make('Name')->searchable()->sortable(),
            Column::make('Green Bean', 'green_bean.name')->searchable()->sortable(),
            Column::make('Roast Type', 'roast_type.name')->searchable()->sortable(),
            Column::make()->view('admin.coffee.table_actions'),
        ];

I have 2 problems:

  1. When I click on sorting the Roast Type column the values in the Name column change to the Roast type name instead of the Coffee name.

  2. When I click on sorting the Green Bean column, I get this error:

Missing required parameter for [Route: coffees.edit] [URI: coffees/{coffee}/edit] [Missing parameter: coffee]. (View: C:\wamp64\www\highland8.local\resources\views\admin\coffee\table_actions.blade.php)

What am I doing wrong?

BTW, I added some functionality like in the jquery dropdown tables, to show:

  1. A dropdown for the user to select how many records to display on the page
  2. A paragraph that shows how many records are displayed from the total results

Can you please help with my issues?

@gbrits
Copy link

gbrits commented Aug 10, 2022

Did you ever get sorting worting for a relationship, I'm facing the same thing and my table is just turning up empty whenever I sort by a relationship?

@SigalZ
Copy link
Author

SigalZ commented Aug 10, 2022

Hi @gbrits,
Yes I did, I don't remember exactly how.

I think I created my own datatable classes and view where I do the db queries myself.

I can send you the files if you want.

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

No branches or pull requests

2 participants