dadooda / handles_sortable_columns Goto Github PK
View Code? Open in Web Editor NEWSortable Table Columns
License: MIT License
Sortable Table Columns
License: MIT License
I saw the closed issue that another user submitted, and I tried doing something similar, but it doesn't work for me.
Course belongs_to category
Category has_many courses
#View
<%= sortable_column "Category", column: "category_title" %>
##Courses Controller
def index
order = sortable_column_order do |column, direction|
case column
when "category_title"
"category.title #{direction}"
end
end
if params[:query].blank?
@courses = current_account.courses.order(order).paginate(:page => params[:page], :per_page => 15)
else
@courses = current_account.courses.search_by_content(params[:query]).order(order).paginate(:page => params[:page], :per_page => 15)
end
end
Error message:
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "categories"
LINE 1: ...urses" WHERE "courses"."account_id" = 2 ORDER BY categories...
^
: SELECT "courses".* FROM "courses" WHERE "courses"."account_id" = 2 ORDER BY categories.title asc LIMIT 15 OFFSET 0
Also, how would I be able to use the methods I defined in my models?
i.e. test.average_score
=> average_score is not saved in a table but is calculuted in the test.rb model
Hi can you please let me know how to do ajax for this gem.
Present we have
<%= sortable_column "column_name" %> if I click it loading the page, but i want instead of loading total page i want to add ajax.
I haven't seen ajax functionality to this gem. Can you please anyone explain me how to add ajax for this sortable column.
hi
this gem dont use DESC and ASC methode of mysql. i see that it use just ' - ' befor the name of the column used to be sorted.
its there a way to fix it please?
I get the following error when calling sortable_column method. It seems to be caused by some security they added on rails 5.
ArgumentError - Attempting to generate a URL from non-sanitized request parameters! An attacker can inject malicious data into the generated URL, such as changing the host. Whitelist and sanitize passed parameters to be secure.
i cant find the way to change the display of indicator โ and โ .
in css i do:
//
/ sotable table /
//
.asc{
background: url(/images/up_arrow.gif) no-repeat;
}
.desc{
margin-left: 10px;
background-image: url(/images/down_arrow.gif);
}
and in the controller:
handles_sortable_columns do |conf|
conf.class = "SortableLink"
conf.indicator_class = {:asc => "asc", :desc => "desc"}
end
what i did miss !!?
thanks.
Rails 3.0.0
gem install handles_sortable_columns
Gemfile:
gem "handles_sortable_columns"
And restart the server (rails s):
/usr/lib/ruby/gems/1.8/gems/handles_sortable_columns-0.1.1/lib/action_controller/base/handles_sortable_columns.rb:2: uninitialized constant ActionController::Base::Handles (NameError)
from /usr/lib/ruby/gems/1.8/gems/handles_sortable_columns-0.1.1/lib/handles_sortable_columns.rb:3
from /usr/lib/ruby/gems/1.8/gems/handles_sortable_columns-0.1.1/lib/handles_sortable_columns.rb:2:in each' from /usr/lib/ruby/gems/1.8/gems/handles_sortable_columns-0.1.1/lib/handles_sortable_columns.rb:2 from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/runtime.rb:64:in
require'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/runtime.rb:64:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/runtime.rb:62:in
each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/runtime.rb:62:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/runtime.rb:51:in
each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/runtime.rb:51:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler.rb:112:in
require'
from /home/gerard/project/visualpis/config/application.rb:7
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/commands.rb:28:in require' from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/commands.rb:28 from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/commands.rb:27:in
tap'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
Pardon my ignorance, but I am getting this error:
undefined local variable or method `has_sortable_columns' for ModelFunctions:Module
When trying to use the plugin with some methods that I extend via a Module.
I extend the search
method inside my controller by redeclaring it again in the module since I used it with multiple controllers. Is there a way to get the search method in the Module to understand about the sortable columns?
Thanks.
And thanks for the plugin, it's very nice.
in line 132 of sortable_columns.rb:
before_filter(fopts) do |ac|
needs to be changed to before_action
Thanks for a simple and functional plugin. But I have a question:
I have a column that is a lookup of the name of a column in another table.
That is, I have cities.country_id as a column and in the View template I do:
city.country.name
to display the name.
I would like to be able to sort by this column, but the countries.name, not the cities.country_id.
Is this possible with the plugin? If so how?
Thanks.
From examining the code, it looks like the sort params should be merged with any other params that should be preserved (such as a search param) here:
sortable_columns.rb line 257: url = url_for(params.merge( . . . .
but my sort links are always generated with just direction= and sort= params - it seems so simple, I can't imagine what could go wrong. Any thoughts?
Rails 3.2.13 and handles_sortable_columns (0.1.4)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.