I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

Adding special columns

I hope you like extended columns for projects and users listings which were introduced in 0.1.0! I also hope you will like that you can add your own extended columns! This is mostly useful for plugins but can also be used to add custom extended columns.

To request an extended column post a feature request with the “Special column” issue category, suggest a name and descibe what this column should display.

On this page I explain how to add new extended columns to projects and users listing. Here I add “Subscriptions” columns. These columns will display the total count of subscriptions to a project in the projects listing and the total count of subscriptions by a user in the users listing. These columns are real-life examples and are added by my Subscription plugin.

For the list of currently available special columns check this page...

Extended column

An extended column is implemented using the ExtendedColumn class.

The initializer of this class accepts one argument:

ExtendedColumn.new(:subscriptions)

And the following options:

Parameters Sample value Description
:align :center HTML alignment, other samples: :right, :left.
:caption :label_subscription_plural Used as a translation identifier. If not specified uses "field_#{:name}".
:css_classes 'extended-column' Sets CSS class. If not specified uses :name.
:value :description Specifies attribute to get value from or function for getting value. Uses :name if not specified.

Samples

The following code ensures that the Extended Fields plugin is installed:

if Project.respond_to?(:add_available_column)
    ...
end

Adding extended column to projects listing:

To add the "Subscriptions" extended column to projects listing add the following code to plugin's init.rb:

if Project.respond_to?(:add_available_column)
    Project.add_available_column(ExtendedColumn.new(:subscriptions,
                                                    :caption => :label_subscription_plural,
                                                    :value => lambda { |project|
                                                        ProjectSubscriber.count(:conditions => [ "project_id = ?", project.id ]) },
                                                    :align => :center))
end

Adding extended column to users listing:

To add the "Subscriptions" extended column to users listing add the following code to plugin's init.rb:

if User.respond_to?(:add_available_column)
    User.add_available_column(ExtendedColumn.new(:subscriptions,
                                                 :caption => :label_subscription_plural,
                                                 :value => lambda { |user|
                                                     ProjectSubscriber.count(:conditions => [ "user_id = ?", user.id ]) },
                                                 :align => :center))
end
Terms of use | Privacy policy