1

I have been looking at Simple Datatables but the documentation and example provided are not very clear. It appears to implement jsonify and utilize a template handler but I am not sure. Also the provided code does not compile; is the author using some other gem to parse the views? For example, it says to put this in your search view...

@products.each do |product|
  json << [product.name, product.manufacturer.name]
end

which I assuming has to be translated to...

<%= @products.each do |product| %>
 <% json << [product.name, product.manufacturer.name] %>
<% end %>

but it comes back and says 'undefined local variable or method 'json' for class blah blah'

same type of deal for the index view. The example says to just throw this in your view,

%table#products
  %thead
    %tr
      %th= Product.human_attribute_name :name
      %th= Product.human_attribute_name :manufacturer

  %tbody

but if I do that it simply puts that raw text in my view. Again, it seems like the author is using some gem to parse his views but not referencing it in the docs. Any thoughts? Thanks!

Edit:
Ok, so I got the table to load correctly by calling it as a table... duh...

<table class="products">
  <thead>
  <tr>
    <th>Name</th>
    <th>Manufacturer</th>

 </thead>
 <tbody></tbody>
 </table>

but it is now telling me it has no data to load. I checked the route and /search works but /search.datatables comes back telling me there is no template. Thanks again,

0

2 Answers 2

1

The author isn't using any other gem as far as I can tell.

@products.each do |product|
   json << [product.name, product.manufacturer.name]
end

You need to put the above code into a search.datatables.jsonify file instead of just search.datatables.

Also you should change the class="products" to id="products" in your table markup. You will also want to put the corresponding id's into the th tags too.

Finally the javascript was a bit mangled too, try the following

$("#products").dataTable( {
   "sAjaxSource"     : "/products/search.datatables",
   "aaSorting"       : [[0, 'asc']],
   "aoColumns"       : [
      {"sName":"name"},
      {"sName":"manufacturer_name"},
],
"bServerSide"     : true,
"fnServerData"    : simpleDatatables
});

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

The index view is using the haml gem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.