【问题标题】:Using Rails 3.1 with DataTables将 Rails 3.1 与数据表一起使用
【发布时间】:2011-09-09 16:18:10
【问题描述】:

在 Rails 3.1 中,推荐与 DataTables 集成的 gem 是什么?

【问题讨论】:

    标签: ruby-on-rails jquery-datatables


    【解决方案1】:

    我正在使用带有引导程序的jquery-datatables-rails gem(twitter-bootstrap-rails gem),它非常完美。上面的 railscast 插曲很棒——但不要将 gem 放在您的资产组中,否则在部署到 heroku 时它将不起作用(因为资产组未用于生产)。

    将此行放入您的 gemfile 中:

    gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
    

    然后运行:

    bundle install
    

    另外,请确保将此行放入您的 application.rb:

    config.assets.initialize_on_precompile = false
    

    将此添加到您的 application.js

    //= require dataTables/jquery.dataTables
    

    如果你使用的是引导程序,这个:

    //= require dataTables/jquery.dataTables.bootstrap
    

    将此添加到您的 application.css:

    *= require dataTables/jquery.dataTables
    

    如果您使用的是引导程序,则为这个:

    *= require dataTables/jquery.dataTables.bootstrap
    

    如果您使用引导程序,请将其添加到您的控制器的 js.coffee 文件中,您正在使用数据表:

    如果您使用流体容器:

    #// For fluid containers
    $('#dashboard').dataTable({
      "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
      "sPaginationType": "bootstrap"
    });
    

    如果您使用的是固定宽度的容器:

    #// For fixed width containers
    $('.datatable').dataTable({
      "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
      "sPaginationType": "bootstrap"
    });
    

    【讨论】:

      【解决方案2】:

      在 Ryan Bates 的 RailsCast 中 (http://railscasts.com/episodes/340-datatables) 他使用 jquery-datatables-rails (https://github.com/rweng/jquery-datatables-rails)

      【讨论】:

        【解决方案3】:

        我自己没用过,但这是可用的:https://github.com/gryphon/simple_datatables

        【讨论】:

        • simpe_datatables 使用 meta_search 已被弃用。我已经使用过它,但在分页和使用多个表格时遇到了一些问题。现在我正在实现我自己的 gem。
        【解决方案4】:

        以下 gem 链接可能是相关的:https://github.com/artellectual/rails-datatables

        这个 gem 是 simple_datatables gem(Allan 提到)的一个分支,但它也支持使用 kaminari 进行分页,并使用元搜索 gem 使用 ajax 搜索表数据。

        【讨论】:

          猜你喜欢
          • 2011-12-16
          • 2011-12-19
          • 2012-03-27
          • 2020-11-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-07-14
          • 1970-01-01
          相关资源
          最近更新 更多