Open aldrienht opened 8 years ago
look at here - https://github.com/ajahongir/ajax-datatables-rails/blob/v-0-4-0/lib/ajax-datatables-rails/base.rb#L10
init method already accepts options.
so you can any time access to @options[:session]
Hi @ajahongir , thank you very much! my question #1 was solved. what does it mean having the error above when trying to search using the default search bar of dataTable, as in question #2 ?
well, in how-to sample project I am having same query:
SELECT COUNT(*) FROM (SELECT cities.*, timezone AS custom_column FROM "cities" WHERE (((("cities"."id" = 0 OR CAST("cities"."name" AS VARCHAR) LIKE '%a%') OR custom_column LIKE 'a%') OR CAST("cities"."iata" AS VARCHAR) LIKE '%a%') OR "cities"."country_id" = 1) GROUP BY cities.country_id) AS foo'
and works well.
you can try to override counting method like:
class TestDatatable < AjaxDatatablesRails::Base
def as_json(options = {})
{
recordsTotal: get_raw_records.count(:all),
recordsFiltered: filter_records(get_raw_records).count(:all),
data: data
}
end
end
First I tried to clone this repo, and successfully run it without error. Aside from I change the branch: to 'v-0-4-0'.
Question #1
For example I need to may if statement that checks the session role etc.
in controller index: something like:
After that, how can I get the session parameter inside ?
class TestDatatable < AjaxDatatablesRails::Base
Question #2 I'm getting some error when try to seach (i didn't implement the individual search per column, ONLY the default search).
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR) LIKE '%a%' OR CAST(
applicants
.name
AS VARCHAR) LIKE '%a%') OR CAST(' at line 1: SELECT COUNT() FROM (SELECTapplicants
._ FROMapplicants
WHEREapplicants
.status
= 'In-progress' AND (((((((((CAST(applicants
.profile_file_name
AS VARCHAR) LIKE '%a%' OR CAST(applicants
.name
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.project_id
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.gender
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.birth_date
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.age
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.country_id
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.marital_status
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.last_academic
AS VARCHAR) LIKE '%a%') OR CAST(applicants
.religion_id
AS VARCHAR) LIKE '%a%')) AS foo _Please help to figure it out.
Thank you!