Skip to content

Instantly share code, notes, and snippets.

@michalg-
Last active August 29, 2015 14:17
Show Gist options
  • Save michalg-/8d46e42f98e98d20c541 to your computer and use it in GitHub Desktop.
Save michalg-/8d46e42f98e98d20c541 to your computer and use it in GitHub Desktop.
app/datatables/product_datatable.rb
class ProductDatatable < AjaxDatatablesRails::Base
def_delegators :@view, :render, :to_price
def sortable_columns
@sortable_columns ||= [
'Product.name',
'Prototype.name',
'ProducersDictionary.name',
'ProductCategory.name',
'Product.margin'
]
end
def searchable_columns
@searchable_columns ||= [
'Product.name',
'Prototype.name',
'ProducersDictionary.name',
'ProductCategory.name'
]
end
private
def data
records.map do |record|
[
record.name,
record.prototype_name,
record.producers_dictionary_name,
record.product_category_name,
"#{to_price(record.margin)} %",
render('/products/products_list_buttons', product: record)
]
end
end
def get_raw_records
options[:search_params] ||= {}
#we join associations inside
ProductSearch.new(options[:search_params].merge!(current_user: options[:current_user])).search
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment