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
Problem with columns definition #159
Comments
I think this functionality is part of what @ajahongir implemented on the |
@nevedimko can you show your my_datatable.rb? |
@ajahongir Yes, sure. It looked like this: class SubjectDatatable < AjaxDatatablesRails::Base
def sortable_columns
# Declare strings in this format: ModelName.column_name
@sortable_columns ||= [
'Subject.id',
'Subject.name',
'Subject.suggest'
]
end
def searchable_columns
# Declare strings in this format: ModelName.column_name
@searchable_columns ||= [
'Subject.id',
'Subject.name',
]
end
private
def data
records.map do |record|
[
# comma separated list of the values for each cell of a table row
# example: record.attribute,
'id' => record.id,
'name' => record.name,
'suggest' => record.suggest
]
end
end
def get_raw_records
Subject.all
end
# ==== Insert 'presenter'-like methods below if necessary
end I'm trying to make friends angular-datatables with ajax-datatables-rails Also I have a problem with using Also when I'm using a custom select like |
well, I recomend you use latest version(0.4) of the gem and you will have search & sort out of the box. try to define like this: class SubjectDatatable < AjaxDatatablesRails::Base
def view_columns
@view_columns ||= {
id: { source: "Subject.id", cond: :eq },
name: { source: "Subject.name" },
suggest: { source: "Subject.suggest" }
}
end
private
def data
records.map do |record|
[
# comma separated list of the values for each cell of a table row
# example: record.attribute,
'id' => record.id,
'name' => record.name,
'suggest' => record.suggest
]
end
end
def get_raw_records
Subject.all
end
# ==== Insert 'presenter'-like methods below if necessary
end also look at this sample project https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to |
also you can see here custom column sample too - https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to/blob/master/app/datatables/city_datatable.rb |
@ajahongir Thanks for your response. I tried to work with version 0.4 and this is my_datatable.rb class SubjectDatatable < AjaxDatatablesRails::Base
def view_columns
@view_columns ||= {
id: { source: "Subject.id", cond: :eq },
name: { source: "Subject.name" },
suggest: { source: "Subject.suggest" },
usage_count: { source: "usage_count" }
}
end
private
def data
records.map do |record|
[
# comma separated list of the values for each cell of a table row
# example: record.attribute,
'id' => record.id,
'name' => record.name,
'suggest' => record.suggest,
'usage_count' => record[:usage_count]
]
end
end
def get_raw_records
Subject.select('subjects.*, COUNT(users.id) AS usage_count')
.joins('LEFT JOIN users ON subjects.name = users.major')
.group('subjects.id')
end
# ==== Insert 'presenter'-like methods below if necessary
end If I set If |
@nevedimko make sure that using right version of the gem. try to include like this: |
Great. Thanks. Now there's just one issue: Total count works incorrect with my |
@nevedimko try to override as_json method as def as_json(options = {})
{
recordsTotal: get_raw_records.count(:all).count,
recordsFiltered: get_raw_records.model.from("(#{filter_records(get_raw_records).except(:limit, :offset, :order).to_sql}) AS foo").count,
data: data
}
end |
I already did so. |
круто |
Fixed in master branch. |
I want to use named columns. Like
I set the following in my_datatable.rb
And after that I get an error:
no implicit conversion from nil to integer
The text was updated successfully, but these errors were encountered: