Sha256: 2ae7602bfcf29365a61908dc195526745de60184e7bcbc9ca17bc23696a8c8f8
Contents?: true
Size: 942 Bytes
Versions: 2
Compression:
Stored size: 942 Bytes
Contents
module Madmin module SortHelper def sortable(column, title, options = {}) matching_column = (column.to_s == sort_column) direction = sort_direction == "asc" ? "desc" : "asc" link_to resource.index_path(sort: column, direction: direction), options do concat title if matching_column concat " " concat tag.i(sort_direction == "asc" ? "▲" : "▼") end end end def sort_column resource.sortable_columns.include?(params[:sort]) ? params[:sort] : default_sort_column end def sort_direction ["asc", "desc"].include?(params[:direction]) ? params[:direction] : default_sort_direction end def default_sort_column resource.try(:default_sort_column) || (["created_at", "id", "uuid"] & resource.model.column_names).first end def default_sort_direction resource.try(:default_sort_direction) || "desc" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
madmin-1.2.7 | app/helpers/madmin/sort_helper.rb |
madmin-1.2.6 | app/helpers/madmin/sort_helper.rb |