-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from bluerogue251/make_datatables_a_fully_fled…
…ged_model Make Datatable a class instead of a module
- Loading branch information
Showing
7 changed files
with
69 additions
and
101 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class Datatable | ||
def initialize(params, unfiltered_search, columns) | ||
@params = params | ||
@unfiltered_search = unfiltered_search | ||
@columns = columns | ||
end | ||
|
||
def s_echo | ||
params[:sEcho].to_i | ||
end | ||
|
||
def filtered_search | ||
@filtered_search ||= @unfiltered_search.build do | ||
fulltext params[:sSearch] | ||
order_by(sort_column, sort_direction) | ||
paginate page: page, per_page: per | ||
end.execute | ||
end | ||
|
||
def total_record_count | ||
@unfiltered_search.execute.total | ||
end | ||
|
||
def filtered_record_count | ||
filtered_search.total | ||
end | ||
|
||
def data | ||
filtered_search.results | ||
end | ||
|
||
private | ||
|
||
attr_reader :params, :columns | ||
|
||
def page | ||
(params[:iDisplayStart].to_i / per) + 1 | ||
end | ||
|
||
def per | ||
params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10 | ||
end | ||
|
||
def sort_direction | ||
params[:sSortDir_0] == "desc" ? :desc : :asc | ||
end | ||
|
||
def sort_column | ||
columns[params[:iSortCol_0].to_i] | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
json.sEcho datatable.s_echo | ||
json.iTotalRecords datatable.total_record_count | ||
json.iTotalDisplayRecords datatable.total_display_records | ||
json.iTotalDisplayRecords datatable.filtered_record_count | ||
json.aaData data |