-
Notifications
You must be signed in to change notification settings - Fork 227
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
has_scope gem support #280
Comments
format.json { render json: InvoiceDatatable.new(view_context, { current_org: current_organization }) } class Foo < AjaxDatatablesRails::Base
include HasScope
has_scope :featured, :type => :boolean
has_scope :by_degree
has_scope :by_period, :using => [:started_at, :ended_at], :type => :hash
def get_raw_records
apply_scopes(current_organization.invoices).all
end
private
def current_organization
options[:current_org]
end
end Don't use |
what I did was I passed in the query to the the a datatable
and in the datatable file
|
It sounds like an anti pattern. Does the solution I propose work? (I didn't try it, just read the code of has_scope) |
ohh I see. will try your code above I'm guessing it will loop through the columns and wouldn't be able to read the params defined in the has_scope? |
|
I've updated the example above |
this worked like a charm! and neat code!! |
Ok. I will take a look when I can. |
thanks @n-rodriguez |
@emilenriquez does it work? |
it did work @n-rodriguez thanks! |
Hi @emilenriquez, I would like to use has_scope with ajax call, so I don't need to reload my page, do you have any idea how can do it? For example, I would add a checkbox for show/hide inactive users (it is a boolean in the table), if user check or uncheck the checkbox I would like to trigger the call and refresh my table and also when a user clicks in sort arrows in a specific column this value for inactive users can be included in the ajax call. Thanks for any help here. |
@emilenriquez it looks it should be a good option for including my custom params into the ajax call, but i do not find how to trigger the datatable ajax call when the user clicks the show the inactive users https://datatables.net/examples/server_side/custom_vars.html |
@cesar82 Have you been able to figure out how to refresh your DataTable without a page reload? |
@andreibondarev yes! This method DataTable().ajax.reload() reloads the table and take the user to page 1, if you want to keep the current page use this way DataTable().ajax.reload(null, false) Thanks |
https://github.com/plataformatec/has_scope
this gem simplifies the need to create long hard coded queries that makes the function bloated.
is there any chance we can use this to query the data?
The text was updated successfully, but these errors were encountered: