Skip to content

Instantly share code, notes, and snippets.

@andyhite
Last active December 20, 2015 09:30
Show Gist options
  • Save andyhite/6108412 to your computer and use it in GitHub Desktop.
Save andyhite/6108412 to your computer and use it in GitHub Desktop.
# Do you want something like this...
class CitiesDatatable < Datatable
datatable class_name: 'City', search_keys: [:name]
end
# where you would access the Datatable information like this, where self == controller.view_context ...
cities_datatable = CitiesDatatable.new(self)
cities_datatable.to_json # => { sEcho: 1, iTotalRecords: 20, iTotalDisplayRecords: 10, aaData: [...] }
# or something like this ...
class City < ActiveRecord::Base
include Datatables
define_datatable search_keys: [:name]
end
# where you would access the Datatable information via something like this, where self == controller.view_context ...
City.datatable(self) # => { sEcho: 1, iTotalRecords: 20, iTotalDisplayRecords: 10, aaData: [...] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment