bogdan / datagrid

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

User's current time zone #320

Closed fzf closed 7 months ago

fzf commented 7 months ago

Great gem! I am loving playing around with it.

I am wondering if there is any way to inject the users current time zone similar to how https://github.com/basecamp/local_time works.

Thanks!

fzf commented 7 months ago

Nevermind. You can use the html-columns solution to just pass in the local_time.

bogdan commented 7 months ago

I usually do some workarounds like:

time_column(:created_at)

def self.time_column(name, &block)
  column(name) do |model|
    format(block&.call || model.public_send(name)) do |value|
      local_time(value) # or any other helper
    end
  end
end
fzf commented 7 months ago

@bogdan yes, that is a much better pattern. Thank you!