Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Makes it easy to ship data to a jQuery DataTable from ActiveRecord or Mongoid.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO
Octocat-spinner-32 data_table.gemspec
README.rdoc

Data Table

Makes it easy to ship data to a jQuery DataTable from ActiveRecord or Mongoid.

Quick example:

in your javascript:

$(".providers-data-table").dataTable({"bJQueryUI"       : true,
                                      "bProcessing"     : true,
                                      "bAutoWidth"      : false,
                                      "sPaginationType" : "full_numbers",
                                      "aoColumns"       : [{"sType" : "html"}, null, null, null, null],
                                      "aaSorting"       : [[0, 'asc'], [1, 'asc']],
                                      "bServerSide"     : true,
                                      "sAjaxSource"     : "/providers.json" }).fnSetFilteringDelay();

Note: the fnSetFilteringDelay() call isn't required but highly recommended: datatables.net/plug-ins/api#fnSetFilteringDelay

in your controller:

class ProvidersController < ApplicationController

  def index
    respond_to do |wants|
      wants.html
      wants.json do
        render(:json => Provider.for_data_table(self, %w(name fein categories.name county state), %w(name fein)) do |provider|
          ["<%= link_to(provider, provider) %>", provider.fein, provider.category.name, provider.county, provider.state]
        end)
      end
    end
  end

end

in your view (assuming HAML):

%table.providers-data-table
  %thead
    %tr
      %th Name
      %th FEIN
      %th Category
      %th County
      %th State

  %tbody

Patches welcome, enjoy!

Copyright

Copyright © 2010 Jason Dew. See LICENSE for details.

Something went wrong with that request. Please try again.