开发者

Table component in rails

开发者 https://www.devze.com 2023-03-25 22:48 出处:网络
I\'m looking for a simple table component to use in my rails application. I\'ll need filters & page navigation on that.

I'm looking for a simple table component to use in my rails application. I'll need filters & page navigation on that.

To explain more, I've quite a few table views in my app for various models, instead of coming up with markup separately, I would like to have a table_for similar to form_for. Also the table_for should be capable of rendering data from associations too.

Will be great if there is anything out there. There is something like what I want here 开发者_开发问答- http://www.shaneharvie.com/2007/03/tablefor-erb-template.html. It has to be improvised to suit my needs.


A component I am very happy with, is wice_grid. It builds the query, pagination, .. for you, allows to filter on columns very easily.

A simple example (from the documentation) : suppose you have a model Task, and you want the build the index/table. Then in the controller you write the following:

@tasks_grid = initialize_grid(Task)

... and in the View:

<%= grid(@tasks_grid) do |g|
  g.column :column_name => 'ID', :attribute_name => 'id'
  g.column :column_name => 'Title', :attribute_name => 'title'
  g.column  :column_name => 'Description', :attribute_name => 'description'
  g.column  :column_name => 'Archived', :attribute_name => 'archived' do |task|
    task.archived? ? 'Yes' : 'No'
  end

  g.column   do |task|
    link_to('Edit', edit_task_path(task))
  end
end -%>

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消