bogdan / datagrid

Gem to create tables grids with sortable columns and filters
MIT License
1.02k stars 116 forks source link

Can not make decorator work #204

Closed Uysim closed 7 years ago

Uysim commented 7 years ago

I use gem draper

decorate { UserDecorator }

But datagrid did not decorate at all I use datagrid version 1.5.1

bogdan commented 7 years ago

Can you show more full version of code you work with?

Uysim commented 7 years ago
class UsersGrid

  include Datagrid

  scope do
    User
  end

  decorate { |user| UserDecorator.new(user) }

  filter(:name, header: -> { I18n.t('users.index.name') }) do |value, scope|
    scope.where('name iLIKE ?', "%#{value.downcase}%")
  end

  filter(:email, header: -> { I18n.t('users.index.email') })

  filter(:role, :enum, select: User::ROLES.map {|r| [r.humanize, r]},  header: -> { I18n.t('users.index.role') }, class: 'select-material')

  column(:avatar, header: -> { I18n.t('users.avatar') }, order: false, html: true) do |object|
    link_to image_tag(object.avatar.thumb, class: 'circle', alt: object.name), user_path(object)
  end

  column(:name, header: -> { I18n.t('users.index.name') }, html: true ) do |object|
    link_to object.name, user_path(object)
  end
  column(:email, header: -> { I18n.t('users.index.email') })
  column(:role, header: -> { I18n.t('users.index.role') }) do |object|
    object.role.humanize.titleize
  end

  column(:status,  header: -> { I18n.t('users.index.status') }, html: true, order: 'approved, role' ) do |object|
    object.approval_status
  end

  column(:action, header: -> { I18n.t('users.index.action') }, html: true ) do |object|
    render 'users/actions', object: object
  end
end
bogdan commented 7 years ago

I have no problem making it work. Can you show your controller and the view too?

bogdan commented 7 years ago

Closing for inactivity