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

Update WithSorting.php #805

Merged
merged 1 commit into from
Jul 25, 2022
Merged

Update WithSorting.php #805

merged 1 commit into from
Jul 25, 2022

Conversation

pkeogan
Copy link
Contributor

@pkeogan pkeogan commented Jun 9, 2022

All Submissions:

  • [Yes] Have you followed the guidelines in our Contributing document?
  • [Yes] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. [Not Tested] Does your submission pass tests and did you add any new tests needed for your feature?
  2. [Not Applicable] Did you update all templates (if applicable)?
  3. [Not Applicable] Did you add the relevant documentation (if applicable)?
  4. Did you test locally to make sure your feature works as intended? You betcha!

Changes to Core Features:

  • [Not Tested] Have you added an explanation of what your changes do and why you'd like us to include them?
  • [Not Tested] Have you written new tests for your core changes, as applicable?
  • [Not Tested] Have you successfully ran tests with your changes locally?

Not sure if originally tests for the function exists, as the comment above the function is //TODO: Test

Not sure why, but on latest
PHP v8.1.5
Laravel v9.16.0
laravel-livewire-tables v2.7.0

if you invoke the sortable callback on any column such as

Column::make('User', 'last_name')
    ->sortable(function(Builder $query, string $direction) {
        return $query->orderBy('last_name', $direction);
    })
    ->view('some.column.view)

OR

Column::make('Department', 'agency_id')
->sortable(
  function(Builder $query, string $direction) {
      return $query->join('agencies', 'users.agency_id', '=', 'agencies.id')
          ->orderBy('agencies.name', 'ASC');
      }
  )

You will be met with this error when trying to sort.
image

Error relates to an app()->call() within WithSorting.php

// TODO: Test
            if ($column->hasSortCallback()) {
                //this one returns a query to the server that is ONLY the call back
                $this->setBuilder(app()->call($column->getSortCallback(), ['builder' => $this->getBuilder(), 'direction' => $direction]));
                // This one work
                 $this->setBuilder(call_user_func($column->getSortCallback(), $this->getBuilder(), $direction));
            } elseif ($column->isBaseColumn()) {
                $this->setBuilder($this->getBuilder()->orderBy($column->getColumnSelectName(), $direction));
            } else {
                $this->setBuilder($this->getBuilder()->orderByRaw('"'.$column->getColumnSelectName().'"' . ' ' . $direction));
            }

not sure 100% the ramifcations of using app()->call() vs call_user_func but whatever is going on with app()->call() is not working.

@pkeogan
Copy link
Contributor Author

pkeogan commented Jun 9, 2022

This fixes #804

@saleemepoch
Copy link

I am having the same issue with sorting. Eagerly waiting for this to be approved/fixed. Thanks :)

1 similar comment
@cytech
Copy link

cytech commented Jun 29, 2022

I am having the same issue with sorting. Eagerly waiting for this to be approved/fixed. Thanks :)

@rappasoft rappasoft added the Awaiting Next Release Currently merged into development awaiting a release to master label Jul 25, 2022
@rappasoft rappasoft mentioned this pull request Jul 25, 2022
@rappasoft rappasoft merged commit 0ffd743 into rappasoft:master Jul 25, 2022
@saleemepoch
Copy link

saleemepoch commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Next Release Currently merged into development awaiting a release to master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants