ex_admin icon indicating copy to clipboard operation
ex_admin copied to clipboard

Index sort

Open dmytronasyrov opened this issue 7 years ago • 8 comments

Please help, how to sort grid index as: :grid, columns: 4? I have tried to define order in scope :all but it doesn't call all even by clicking it in scopes panel. In a custom scope like this Ecto returns "expected at most one result but got 10 in query":

from p in Post,
where: not is_nil(p.details),
group_by: [p.id, p.name],
order_by: [asc: p.name]

Something likes this doesn't work too:

query do
%{all: [order_by: [asc: :name]]}
end

dmytronasyrov avatar Jun 05 '17 13:06 dmytronasyrov

Try this for your all scope

scope :all, [default: true], fn(q) ->
    order_by(q, [p], asc: p.name)
end

smpallen99 avatar Jun 05 '17 15:06 smpallen99

I have tried this already, doesn't work. Query: SELECT c0."id", ... c0."inserted_at", FROM "blog"."posts" AS c0 ORDER BY c0."id" DESC LIMIT $1 OFFSET $2 [10, 0]

If I change scope to something other than :all, than there should be group_by:

scope :ordered, [default: true], fn(q) ->
group_by(q, [p], [:id, :name])
|> order_by([p], asc: p.name)
end

And response contains error:

expected at most one result but got 10 in query:
from b in Blog.Post,
  group_by: [b.id, b.name],
  order_by: [asc: b.name],
  select: count(b.id)

I have tried to add |> limit([p], 1) Then app generates two queries. One for All with an order by id, and another one SELECT count(p0."id") FROM "blog"."post" AS p0 GROUP BY p0."id", p0."name" ORDER BY p0."name" LIMIT 1 - this is definitely wrong.

dmytronasyrov avatar Jun 05 '17 15:06 dmytronasyrov

What version of ExAdmin?

smpallen99 avatar Jun 05 '17 15:06 smpallen99

Commit from May 16

dmytronasyrov avatar Jun 05 '17 15:06 dmytronasyrov

I'll try to get some time tonight to look at it. Would be best if you could provide a sample project that reproduces the issue.

smpallen99 avatar Jun 05 '17 15:06 smpallen99

I have tried with your Ex_Admin Demo project. Same bugs. :all - nothing changed, :available - expected at most one result but got 16 in query.

screen shot 2017-06-05 at 19 17 32 screen shot 2017-06-05 at 19 19 09

dmytronasyrov avatar Jun 05 '17 16:06 dmytronasyrov

ok. Thanks, I'll troubleshoot with that.

smpallen99 avatar Jun 05 '17 16:06 smpallen99

Thank you!

dmytronasyrov avatar Jun 05 '17 16:06 dmytronasyrov