Last active
August 29, 2015 14:17
-
-
Save michalg-/8d46e42f98e98d20c541 to your computer and use it in GitHub Desktop.
app/datatables/product_datatable.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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