Skip to content

Allow users to specify which collection/instance variable to use in generating the datatables #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ In your controller:
respond_with @products
end

If you are getting strange results (for instance, iTotalRecords and iTotalDisplayRecords both equal 0, or entirely the wrong collection is used), you might want to specify which collection to use:

respond_with @products, :locals => {:collection => @products}

In your search view:

@products.each do |product|
Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/application.datatables.jsonify
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
total_entries = nil
current_page_entries = 0
collection ||= nil

instance_variables.each do |vn|
v = instance_variable_get(vn)

# if a collection variable was specified, use it only
next if collection && collection != v

next if v.class.name.nil?
if v.class.name.start_with?("MetaSearch::Searches") and v.respond_to?('size')
current_page_entries = v.size
Expand Down