Naxon / nova-field-sortable

Adds sorting functionality to the Laravel Nova's index resource
MIT License
60 stars 23 forks source link

Default Sort on Related #7

Open johnpaulmedina opened 6 years ago

johnpaulmedina commented 6 years ago

I was writing something to extend the default sort when I came across someone linking to your package. I noticed that you are only attaching the sort on the index and it is not able to sort on the related content.

Any plans on doing this or should I write my own?

Naxon commented 6 years ago

Added this to future plans. In the meantime you're more than welcome to make a PR.

gauravmak commented 6 years ago

@johnpaulmedina We can make this work with HasMany and MorphMany relationships already.

To make sure that sorting is done among groups only, we can override buildSortQuery() method on the model.

/**
 * Build eloquent builder of sortable. (For spatie/eloquent-sortable package)
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function buildSortQuery()
{
    return static::query()->where('post_id', $this->post_id);
}
timbroder commented 5 years ago

@gauravmak do you mean you have the UI (the arrows) showing up in the HasMany grouping?

If so, how? Thanks!

gauravmak commented 5 years ago

@timbroder Yes, that was the case as far as I can remember. I was displaying only the records of a group and then sorting had to work among the group records only.