{"id":15512567,"url":"https://github.com/hunterae/table-for","last_synced_at":"2025-04-07T17:08:44.622Z","repository":{"id":1460910,"uuid":"1696724","full_name":"hunterae/table-for","owner":"hunterae","description":"table-for is a table builder for an array of objects, easily allowing overriding of how any aspect of the table is generated","archived":false,"fork":false,"pushed_at":"2024-03-28T22:10:22.000Z","size":252,"stargazers_count":70,"open_issues_count":7,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T14:12:46.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hunterae.png","metadata":{"files":{"readme":"README.rdoc","changelog":"CHANGELOG.rdoc","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-05-03T15:05:52.000Z","updated_at":"2024-03-28T22:03:12.000Z","dependencies_parsed_at":"2024-06-19T04:10:39.110Z","dependency_job_id":"b030ea5b-6253-44d8-9abb-9ff1844a60c1","html_url":"https://github.com/hunterae/table-for","commit_stats":{"total_commits":117,"total_committers":4,"mean_commits":29.25,"dds":0.4273504273504274,"last_synced_commit":"7794e2b81fe334aa492ab1afbeb7165c5cb0d49e"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunterae%2Ftable-for","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunterae%2Ftable-for/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunterae%2Ftable-for/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunterae%2Ftable-for/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hunterae","download_url":"https://codeload.github.com/hunterae/table-for/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694876,"owners_count":20980733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T09:53:43.177Z","updated_at":"2025-04-07T17:08:44.595Z","avatar_url":"https://github.com/hunterae.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"= table-for\n\nTableFor is a table builder for a collection of domain objects. It very easily allows the user to specify \nthe columns to render and to override how the table, the header columns, the rows, and the columns are rendered.\n\n== Installation\n\nAdd this to your Gemfile.\n\n  gem \"table-for\"\n\n== Example\nThe following example is purposely complex (in many cases, there are easier ways to do what is shown) \nin order to show a wide range of features that TableFor is capable of:\n\n  \u003c%= table_for @users, :table_html =\u003e { :class =\u003e \"table table-hover table-bordered\" },\n                        :sortable =\u003e true,\n                        :sort_url =\u003e sort_admin_users_path,\n                        :link_namespace =\u003e :admin,\n                        :data_row_html =\u003e {\n                          :class =\u003e lambda { cycle('success', 'error', 'warning', 'info')},\n                          :id =\u003e lambda { |user| \"user-#{user.id}\" }} do |table| %\u003e\n    \u003c% table.column :data =\u003e \"Modify\", :link_action =\u003e :edit %\u003e\n    \u003c% table.column :data =\u003e \"Show\", :link_url =\u003e lambda { |user| admin_user_path(user) } %\u003e\n    \u003c% table.column :data =\u003e \"Show 2.0\", :link =\u003e true %\u003e\n    \u003c% table.column :email, :header =\u003e \"Email Address\" %\u003e\n    \u003c% table.column :first_name, :formatter =\u003e :downcase %\u003e\n    \u003c% table.column :last_name, :formatter =\u003e lambda { |last_name| last_name.upcase } %\u003e\n    \u003c% table.column :created_at, :formatter =\u003e [:strftime, \"%m/%d/%y %I:%M %p\"] %\u003e\n    \u003c% table.column :updated_at,\n                    :header =\u003e lambda {\n                      content_tag(:span, :class =\u003e \"badge badge-success\") do\n                        \"Last Updated\"\n                      end\n                    },\n                    :sortable =\u003e false,\n                    :header_column_html =\u003e { :style =\u003e \"background-color:orange\" },\n                    :data =\u003e lambda { time_ago_in_words table.current_row.updated_at } %\u003e\n    \u003c% table.column :full_name, :header =\u003e \"Full Name\", :order =\u003e \"last_name, first_name\" do |user| %\u003e\n      \u003c%= \"#{user.first_name} #{user.last_name}\" %\u003e\n    \u003c% end %\u003e\n    \u003c% table.header :full_name do |column, options| %\u003e\n      \u003c%= table.header_sort_link(column, options) do %\u003e\n        \u003cspan class=\"label label-important\"\u003eFULL NAME\u003c/span\u003e\n      \u003c% end %\u003e\n    \u003c% end %\u003e\n    \u003c% table.column :data =\u003e \"Delete\", :link_method =\u003e :delete, :link_confirm =\u003e \"Are you sure?\" %\u003e\n    \u003c% table.footer do %\u003e\n      \u003cdiv class=\"pull-right\"\u003e\n        \u003c%= will_paginate @users %\u003e\n      \u003c/div\u003e\n    \u003c% end %\u003e\n  \u003c% end %\u003e\n\nProduces (with Twitter Bootstrap):\n\n{\u003cimg src=\"https://raw.github.com/hunterae/table-for/master/example_table.png\"\u003e}[http://example.com]\n\nFor detailed instructions on how to run this example, along with comments on every line of the above table,\ncheck out the {Example Details}[https://github.com/hunterae/table-for/blob/master/example.rdoc].\n\n== table_for options\nThe first argument to the table_for call will always be the array of domain objects. The second argument is a hash\nand is optional. It is any combination of the following options:\n\nsortable::\n  (defaults to false)\n  Sets whether all columns are sortable by default.\n  If this field is set to true, each column header will be generated as a link.\n    \u003c%= table_for @users, :sortable =\u003e true %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nsort_url::\n  (defaults to the current path)\n  Sets the url for the header column links. This will only affect columns that are sortable.\n    \u003c%= table_for @users, :sortable =\u003e true,\n                          :sort_url =\u003e sort_admin_users_path %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nlink_namespace::\n  (defaults to nil)\n  Sets the default namespace for any links generated in the columns.\n  For example, a link_namespace of admin would try to build links within the admin namespace in the routes.\n  This can be specified as a string, an array, a domain object, or a symbol,\n    \u003c%= table_for @users, :link_namespace =\u003e [:admin, @post, :comments] %\u003e\n      \u003c% table.column :first_name, :link =\u003e true %\u003e\n    \u003c% end %\u003e\ntable_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the table element.\n    \u003c%= table_for @users, :table_html =\u003e { :id =\u003e \"my-table\",\n                                           :class =\u003e \"table table-bordered\",\n                                           :cellpadding =\u003e 2 } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nthead_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the thead element.\n  Note: If TableFor.config.thead_tag is set to nil, the thead surrounding element for the\n  header row will not be rendered.\n    \u003c%= table_for @users, :thead_html =\u003e { :id =\u003e \"thead-id\" } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nheader_row_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the header row (tr) element.\n    \u003c%= table_for @users, :header_row_html =\u003e { :style =\u003e 'color: orange' } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nheader_column_html::\n  (defaults to {})\n  Hash to specify the styles, classes, id, and other attributes applied to the header column (th) element.\n  The values in this hash can each be a string or a Proc that takes (optionally) the column object as a parameter.\n    \u003c%= table_for @users, :header_column_html =\u003e\n      { :style =\u003e \"font-weight: bold\",\n        :class =\u003e lambda {|column| \"#{column.name}_header\" } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\ntbody_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the tbody element.\n  Note: If TableFor.config.tbody_tag is set to nil, the tbody surrounding element for the\n  table data rows will not be rendered.\n    \u003c%= table_for @users, :tbody_html =\u003e { :id =\u003e \"body-id\" } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\ndata_row_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to each data row element (tr).\n  The values in this hash can each be a string or a Proc that takes (optionally) the current record as a parameter\n    \u003c%= table_for @users, :data_row_html =\u003e\n      { :class =\u003e lambda { cycle('success', 'error', 'warning', 'info')}, \n        :id =\u003e lambda { |user| \"user-#{user.id}\" } } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\ndata_column_html::\n  (defaults to {})\n  Hash to specify the styles, classes, id, and other attributes applied to the data column (td) element.\n  The values in this hash can each be a string or a Proc that takes (optionally) the current_record and\n  (also optionally) the column object as parameters\n    \u003c%= table_for @users, :data_column_html =\u003e\n      { :style =\u003e \"font-weight: bold\", \n        :id =\u003e lambda { |record, column| \"record-#{record.id}-#{column.name}\"\n      }} do |table| %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\ntfoot_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the tfoot element.\n  Note: If TableFor.config.tfoot_tag is set to nil, the tfoot surrounding element for the\n  footer row will not be rendered.\n    \u003c%= table_for @users, :tfoot_html =\u003e { :id =\u003e \"tfoot-id\" } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nfooter_row_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the footer row (tr) element.\n    \u003c%= table_for @users, :footer_row_html =\u003e { :style =\u003e 'color: orange' } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nfooter_column_html::\n  (defaults to nil)\n  Hash to specify the styles, classes, id, and other attributes applied to the footer column (td) spanning the entire footer row.\n    \u003c%= table_for @users, :footer_column_html =\u003e\n      { :style =\u003e 'color: orange' } %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\n\n== table_for column options\nEach individual table column can specify it's own set of options, which can override any options \napplied globally in the table options.\n\nThe first argument to the column is optional and represents the name of the column. \nIf specified, it must be unique to the table, and TableFor will attempt to use this \nfield to lookup the value to display in the record, as well as the name to apply to the header column.\n\nFor example, \u003c% table.column :first_name %\u003e will output the first_name field for each record passed to the table. \n\nIf a :header option is not specified for the individual column, it will use this first argument to \ncheck for a translation key to give the header of the column a name (see below under Internationalization). \nFailing to find a translation key, it will titleize \"first_name\" to \"First Name\" and use\nthat label for the header of the column.\n\nThe second argument (or first argument if the name of the column is ommitted) to a table column is a hash and is also optional. It is any combination of the following options:\n\ndata::\n  (defaults to nil, unless specified on the entire table)\n  Either an object instance (on which #to_s will be invoked) or a Proc\n  (which can optionally take the current row as an option), representing the text to be shown\n  in the data cell of the column.\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :data =\u003e \"Edit\" %\u003e\n      \u003c% table.column :name, :data =\u003e\n        lambda {|user| user.name.underscore.upcase } %\u003e\n    \u003c% end %\u003e\nformatter::\n  (defaults to nil, unless specified on the entire table)\n  Either a method name, and array with the method to invoke and its arguments, \n  or a Proc (which will be passed the value requiring formatting, based on the current column's name).\n  The :formatter argument will only work if the column name has been specified.\n  In such a case, the current iteration row will be sent the name of the column, and the resulting value will be\n  what's being formatted. If there is a simple method that needs to be applied to the result, that method name can\n  be specified as the formatter, or a series of method names (shown in examples below):\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :id, :formatter =\u003e :ordinalize %\u003e\n      \u003c% table.column :created_at, :formatter =\u003e [:strftime, \"%m/%d/%Y\"] %\u003e\n      \u003c% table.column :first_name, :formatter =\u003e\n        lambda {|first_name| first_name.downcase } %\u003e\n      \u003c%# THE FOLLOWING IS INVALID %\u003e\n      \u003c% table.column :formatter =\u003e :ordinalize %\u003e\n    \u003c% end %\u003e\nheader::\n  (defaults to nil, unless specified on the entire table)\n  Either false, an object instance (on which #to_s will be invoked) or a Proc\n  (which can optionally take the current column as an option),\n  representing the text to be shown in the header cell of the column. If the :header option is not specified,\n  and no column name is specified (the first argument to the column), then no text will be displayed in the\n  header cell.\n    \u003c%= table_for @users,\n      :header =\u003e lambda { |column| \n        I18n.t(\"tables.headers.#{column.name.to_s.underscore}\",\n          :default =\u003e column.name.to_s.titleize)\n      } do |table| %\u003e\n      \u003c% table.column :id, :header =\u003e false %\u003e\n      \u003c% table.column :first_name, :header =\u003e \"FIRST NAME\" %\u003e\n      \u003c% table.column :last_name %\u003e\n    \u003c% end %\u003e\nsortable::\n  (defaults to false, unless specified on the entire table)\n  Whether this particular column is sortable, which will render a sort link around the header name with a sort_mode\n  field alternating between values 'asc', 'desc', and 'reset'\n    \u003c%= table_for @users, :sortable =\u003e true do |table| %\u003e\n      \u003c% table.column :id, :sortable =\u003e false %\u003e\n      \u003c% table.column :first_name %\u003e\n    \u003c% end %\u003e\nsort_url::\n  (defaults to \"\", a.k.a. the current url, unless specified on the entire table)\n  The sort url that sort links should be generated with\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :first_name, :sortable =\u003e true,\n                                   :sort_url =\u003e sort_admin_users_path %\u003e\n    \u003c% end %\u003e\norder::\n  (defaults to the current column's name)\n  The sort order (either a string or symbol) that sort links should be generated with\n    \u003c%= table_for @users, :sortable =\u003e true do |table| %\u003e\n      \u003c% table.column :first_name, :order =\u003e :fname %\u003e\n      \u003c% table.column :last_name, :order =\u003e \"lname\" %\u003e\n      \u003c% table.column :full_name, :order =\u003e \"lname,fname\" %\u003e\n    \u003c% end %\u003e\n  Note: In the last example, the controller would likely need to split the order param on the comma,\n  and apply the sort_mode to each field in the split, i.e.\n    params[:order].split(\",\").map do |field|\n      \"#{field} #{params[:sort_mode]}\"\n    end.join(\",\")\nlink_url::\n  (defaults to nil, unless specified on the entire table)\n  Either a string or a Proc (which can optionally take the current record being iterated on)\n  which wraps the data columns content in a link.\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :id, :link_url =\u003e\n        lambda {|user| edit_admin_user_path(user) } %\u003e\n      \u003c% table.column :header =\u003e false,\n                      :data =\u003e \"DELETE\",\n                      :link_method =\u003e :DELETE,\n                      :link_url =\u003e lambda { |user| admin_user_path(user) } %\u003e\n    \u003c% end %\u003e\nlink_action::\n  (defaults to nil)\n  An alternative to link_url, link_action takes advantage of Rails' url_for method to generate the url to a specific action\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :data =\u003e \"Edit\", :link_action =\u003e :edit %\u003e\n      \u003c% table.column :data =\u003e \"Delete\", :link_action =\u003e :delete\n        # assuming there is a GET delete route defined %\u003e\n      \u003c% table.column :data =\u003e \"Show\", :link =\u003e true %\u003e\n    \u003c% end %\u003e\nlink_method::\n  (defaults to nil)\n  The HTML method to be used to trigger the link (GET/PUT/POST/DELETE)\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :data =\u003e \"Delete\", :link_method =\u003e :DELETE %\u003e\n    \u003c% end %\u003e\nlink_confirm::\n  (defaults to nil)\n  A confirmation message (javascript) that will be displayed when the user clicks the link\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :data =\u003e \"Delete\", :link_method =\u003e :DELETE,\n                      :link_confirm =\u003e\n                        \"Are you sure you want to delete this user?\" %\u003e\n    \u003c% end %\u003e\nlink_html::\n  (defaults to {}, unless specified on the entire table)\n  Hash to specify the styles, classes, id, and other attributes applied to the link element.\n    \u003c%= table_for @users do |table| %\u003e\n      \u003c% table.column :data =\u003e \"Delete\", :link_method =\u003e :DELETE,\n                      :link_html =\u003e\n                        {:style =\u003e \"color: RED; font-weight: BOLD\"} %\u003e\n    \u003c% end %\u003e\nlink_namespace::\n  (defaults to nil, unless specified on the entire table; normally this option would be specified on the entire table)\n  Sets the namespace for the link.\n  For example, a link_namespace of admin would try to build the link within the admin namespace in the routes.\n  This can be specified as a string, an array, a domain object, or a symbol,\n    \u003c%= table_for @users %\u003e\n      \u003c% table.column :first_name, :link_namespace =\u003e\n        [:admin, @post, :comments], :link =\u003e true %\u003e\n    \u003c% end %\u003e\nlink::\n  (defaults to false)\n  Sets whether the column's content should render as a link (this can also be accomplished by setting :link_url,\n  :link_action, :link_method, or :link_confirm). Set this to true if you are trying to render a show link, since\n  specifying :link_action as :show would break the call to url_for.\n    \u003c%= table_for @users %\u003e\n      \u003c% table.column :id, :link =\u003e true %\u003e\n    \u003c% end %\u003e\ndata_column_html::\n  (defaults to {}, unless specified on the entire table)\n  Hash to specify the styles, classes, id, and other attributes applied to the data column (td) element.\n  The values in this hash can each be a string or a Proc that takes (optionally) the current_record and\n  (also optionally) the column object as parameters\n    \u003c%= table_for @users, :data_column_html =\u003e\n      { :style =\u003e \"font-weight: bold\", \n        :id =\u003e lambda { |record, column| \"record-#{record.id}-#{column.name}\"\n      }} do |table| %\u003e\n      \u003c% table.column :first_name %\u003e\n      \u003c% table.column :last_name, :data_column_html =\u003e\n        {:style =\u003e \"color: red\"} %\u003e\n    \u003c% end %\u003e\nheader_column_html::\n  (defaults to {}, unless specified on the entire table)\n  Hash to specify the styles, classes, id, and other attributes applied to the header column (th) element.\n  The values in this hash can each be a string or a Proc that takes (optionally) the column object as a parameter.\n    \u003c%= table_for @users, :header_column_html =\u003e\n      { :style =\u003e \"font-weight: bold\",\n        :class =\u003e lambda {|column| \"#{column.name}_header\" } %\u003e\n      \u003c% table.column :first_name %\u003e\n      \u003c% table.column :last_name, :header_column_html =\u003e\n        {:style =\u003e \"font-size: 20px\"} %\u003e\n    \u003c% end %\u003e\n\n== table_for header options\nShould you require more control over how a particular header column renders, the default rendering for particular\ncolumn can easily be replaced. This can be accomplish using the header method within a table_for declaration:\n\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.header :first_name do %\u003e\n      Custom Header Code\n    \u003c% end %\u003e\n    \u003c% table.column :first_name %\u003e\n  \u003c% end %\u003e\n\nNote: to specify the :header_column_html (the styles / classes to be applied to the th element),\nthis should still be done on the column call:\n\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.header :first_name do %\u003e\n      \u003c%= link_to \"First Name\", :sort_mode =\u003e\n        (params[:sort_mode] == \"asc\" ? \"desc\" :\n          (params[:sort_mode] == \"desc\" ? \"reset\" : \"asc\")) %\u003e\n    \u003c% end %\u003e\n    \u003c% table.column :first_name, :header_column_html =\u003e {\n      :class =\u003e \n         lambda { params[:sort_mode] == \"asc\" ? \"sorting_asc\" : \n                  (params[:sort_mode] == \"desc\" ? \"sorting_desc\" : \"sorting\") }} %\u003e\n  \u003c% end %\u003e\n\nIn the above example, the first name column header will cycle between classes of\n\"sorting_asc\", \"sorting_desc\", and \"sorting\", while the sort link itself in the header\nwill cycle between sort_mode parameters of \"asc\", \"desc\", and \"reset\". (This is actually\nthe default TableFor sorting behavior)\n\n== table_for footer options\nThere are two ways to specify a footer for a table.\n\nThe first way assumes takes care of rendering the :tfoot element (if TableFor.config.tfoot_tag has not been set to nil),\nthe :tr element, and a single :td element that has its colspan set the number of columns in the table (i.e. it spans the full\nwidth of the table):\n\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.column :first_name %\u003e\n    \u003c% table.column :last_name %\u003e\n    \u003c% table.footer do %\u003e\n      \u003cdiv class=\"pull-right\"\u003e\n        \u003c%= will_paginate @users %\u003e\n      \u003c/div\u003e\n    \u003c% end %\u003e\n  \u003c% end %\u003e\n\nThe second approach will be described below under \"Advanced: Replacing Table Definitions\"\n\n== table_for configuration\nJust as TableFor options can be configured \"globally\" a single table, it can be configured globally for all tables.\n\nThis is accomplished through the TableFor#setup method. Any options that can be specified in the table_for options\ncan also be specified in an initializer method. For example, consider an application where all tables should\nautomatically have the css class \"table table-hover table-bordered\". This is easily accomplished in an initializer:\n\n  TableFor.setup do |config|\n    config.table_html = { :class =\u003e \"table table-hover table-bordered\" }\n  end\n\nGotcha: At this time, you will not be able to configure any TableFor settings that rely on Rails cycles, as the cycle\nwould be maintained globally and would produce unexpected results.\n\nBesides the table_for options that may be configured globally, the following addition options may be set:\n\nthead_tag::\n  (defaults to :thead)\n  Set this to nil if a thead_tag should not be rendered around the header row of the table.\n\ntbody_tag::\n  (defaults to :tbody)\n  Set this to nil if a tbody tag should not be rendered around the body data rows of the table.\n\ntfoot_tag::\n  (defaults to :tfoot)\n  Set this to nil if a tbody tag should not be rendered around the footer row of the table.\n\nsort_modes::\n  (defaults to [:asc, :desc])\n  Sets the order of sort_mode links. A particular sortable column will, by default, generate a sort link\n  with sort_mode set to :asc. If the sort_mode is already :asc for that column, then it generate the sort\n  link with sort_mode set to :desc. Finally, if the sort_mode is already :desc for that column, it will\n  generate a sort link with sort_mode blank.\n\n== Internationalization\n+table-for+ can do some dirty job for you, if you are using i18n by common rails conventions. For example, you have following in your en.yml:\n\n  en:\n    activerecord:\n      attributes:\n        user:\n          id: '#'\n          name: \"Username\"\n          bio: \"Short biography\"\n\nThen, +table-for+ will automatically look up correct translations for column headers. If you are not familiar with i18n, you can always pass a custom header to the column:\n\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.column :parent_name, header: \"Mr. Smith\" %\u003e\n  \u003c% end %\u003e\n\n== ADVANCED: Replacing table definitions\nBecause TableFor was built on top of {Blocks}[https://github.com/hunterae/blocks],\nyou'll have access to some really cool functionality, such as the ability to replace how any aspect\nof your table is defined and rendered.\n\nIf you take a cursory look at the file\n{_table_for.html.erb}[https://github.com/hunterae/table-for/blob/master/app/views/table_for/_table_for.html.erb],\nyou see a series of \"table.define\" calls. These are defining the various elements of the table, and many are recursive\ndefinitions by nature.\n\nFor example, the call to \"table.define :table\", has calls to \"table.render :header\", \"table.render :body\", and \"table.render :footer\".\nBelow the \"table.define :table\", you'll find the calls to \"table.define :header\", \"table.define :body\", and \"table.define :footer\".\nIt shouldn't be hard to see the you're defining the table html element, and the table is made up of a header, a body, and a footer.\nThe header is made up a header row, the body is made up of data rows, and the footer is made up of a footer row. Each of those\nrows is broken down into further definitions.\n\nA question worth asking then is what is really happening here:\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.column :full_name do |user| %\u003e\n      Overriden: \u003c%= \"#{user.first_name} #{user.last_name}\" %\u003e\n    \u003c% end %\u003e\n  \u003c% end %\u003e\n\nBy passing a block in the definition of the :full_name column, we are overriding the default definition for\nthe full_name block (the default definition can be found\n{here}[https://github.com/hunterae/table-for/blob/master/app/views/table_for/_table_for.html.erb#L51-L54]).\nShould we not have specified the block, it would have called #full_name on the user object\nfor each row. But as it is, we've overridden the default behavior for this column.\n\nNote: table.column is an alias to the #queue method, inherited from {WithTemplate}[https://github.com/hunterae/with_template].\nIt works very similar to the \"table.define\" calls, but preserves the order in which blocks are defined. Because the order\nof table columns is important, this is the reason for using #queue instead of #define.\n\nApplying the above principle, it shouldn't be much of a stretch to see that any piece of the TableFor definition may easily\nbe replaced. For example, suppose we didn't like the way footers are {defined}[https://github.com/hunterae/table-for/blob/master/app/views/table_for/_table_for.html.erb#L56-L60].\n\nTo replace this definition, simply #define a footer block:\n\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.column :first_name %\u003e\n    \u003c% table.column :last_name %\u003e\n    \u003c% table.define :footer do %\u003e\n      \u003ctfoot\u003e\n        \u003ctr\u003e\n          \u003ctd colspan=\"\u003c%= table.columns.length %\u003e\"\u003e\n            \u003cdiv class=\"pull-right\"\u003e\n              \u003c%= will_paginate @users %\u003e\n            \u003c/div\u003e\n          \u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/tfoot\u003e\n    \u003c% end %\u003e\n  \u003c% end %\u003e\n\n== ADVANCED: Using \"Before\" and \"After\" hooks\nAnother benefit of TableFor being built on top of {Blocks}[https://github.com/hunterae/blocks] is the ability\nto define before and after blocks. Before blocks will render code before a particular named block is rendered;\nafter blocks will render code after said block. So suppose we wanted to render an extra row after every data row\nrendered that provided some additional data. By examining the TableFor \n{DTD}[https://github.com/hunterae/table-for/blob/master/app/views/table_for/_table_for.html.erb#L38-L43],\nwe can see the block responsible for rendering an individual data row is called :data_row. With this knowledge,\nwe can easily render an extra row after each data_row:\n\n  \u003c%= table_for @users do |table| %\u003e\n    \u003c% table.column :first_name %\u003e\n    \u003c% table.column :last_name %\u003e\n    \u003c% table.after :data_row do %\u003e\n      \u003ctr\u003e\n        \u003ctd colspan=\"\u003c%= table.columns.length %\u003e\"\u003e\n          Some extra data\n        \u003c/td\u003e\n      \u003c/tr\u003e\n    \u003c% end %\u003e\n  \u003c% end %\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunterae%2Ftable-for","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhunterae%2Ftable-for","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunterae%2Ftable-for/lists"}