Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Columns with headers #84

Closed
JoshuaNovak919 opened this issue Nov 24, 2013 · 3 comments
Closed

Dynamic Columns with headers #84

JoshuaNovak919 opened this issue Nov 24, 2013 · 3 comments

Comments

@JoshuaNovak919
Copy link

Is there a way to make a block build columns with custom headers. For example i have users that have associated groups. I'd like to be able to cycle through each group and make that a column header and put an X in the column if the user has that group. New groups can be added so making a ton of custom methods seems very inefficient if i can just make one that can handle all of them.

-Thanks

@eitoball
Copy link
Contributor

Maybe, you could do with __static_column__ like:

class User < ActiveRecord::Base
  belongs_to :group

  comma do
    Group.all.each do |group|
      __static_column__ group.name do |user| user.associated?(group) ? 'X' : '' end
    end
  end  
end

I am not sure if this works...

It is not possible to add columns dynamically, so you have to restart your application when another group is added.

@JoshuaNovak919
Copy link
Author

This worked like a charm. Thanks!! Also, it seems that i don't need to restart the application when the group changes, at least not locally. Is there a way we can add this into the documentation, it would probably be helpful to others.

@eitoball
Copy link
Contributor

Also, it seems that i don't need to restart the application when the group changes, at least not locally. Is there a way we can add this into the documentation, it would probably be helpful to others.

Yeah, comma block is evaluated whenever #to_comma is called. So, it will pick up changes in groups table.

You can fork this project, edit README.markdown file, and send pull-request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants