wice_grid动态添加行

时间:2014-08-13 13:16:05

标签: ruby-on-rails-4 row dynamically-generated wice-grid

我想动态创建一个“详细信息”行,如下所示:

1

我希望能够切换网格上每个项目的详细信息。你能告诉我如何实现这个功能吗? 我正在使用带有wice_grid gem

的rails 4

1 个答案:

答案 0 :(得分:1)

我发现了如何做到这一点:

查看:

<%= grid(@items_grid) do |g|

    g.after_row do |fill, number_of_columns|
        content_tag(:tr, class: 'extra-row') do
              content_tag(:td,
                   content_tag(:div) do
                       # without buffer only the last tag will appear
                       buffer = content_tag(:p,"data1: #{item.add_data1}")
                       buffer += content_tag(:p,"data2: #{item.add_data2}")
                       raw buffer
                   end,
                   colspan: number_of_columns)
         end

  g.column name: "ID", attribute: 'id' do |item|
    item.id
  end

  g.column name: "Data", attribute: 'data' do |item|
    item.data
  end

  g.column do |item|
    button_tag("Details", class: "btn btn-default toggle-trigger")
  end

end -%>

。是:

$(document).on("page:load ready", function(){
    $(".toggle-trigger").click(function(){
        $(this).parents('tr').next('.extra-row').slideToggle("fast");
        return false;
    });
});

.CSS:

.extra-row {
  display: none;
}