Monday 15 June 2015

How to configure Ransack Rails Gem to add NULLS LAST to sort -



How to configure Ransack Rails Gem to add NULLS LAST to sort -

i ransack add together nulls last set nulls lastly sort column.

any way this?

i opened github issue on one: https://github.com/activerecord-hackery/ransack/issues/443

the reply found in thread linked in question above. writing here easier find. apparently need build order string 1 time again , add together null last it.

this solved me (works on columns):

@q.result.except(:order).order("#{@q.sorts.first.name} #{@q.sorts.first.dir} nulls last")

however need exclude when don't have sort parametre, final solution:

@q = project.ransack(params[:q]) @fields = current_user.settings.default_project_fields if @q.sorts.present? @result = @q.result.except(:order).order("#{@q.sorts.first.name} #{@q.sorts.first.dir} nulls last") else @result = @q.result end

ruby-on-rails ransack

No comments:

Post a Comment