code-and-effect / effective_datatables Goto Github PK
View Code? Open in Web Editor NEWAn effective ActiveRecord to Datatables dsl for Ruby on Rails. Make intelligent tables quickly.
License: MIT License
An effective ActiveRecord to Datatables dsl for Ruby on Rails. Make intelligent tables quickly.
License: MIT License
Hi,
Currently the scopes functionality requires a full reload of the page. Wouldn't it be better to avoid a full reload and simply make Datatables reload the page via Ajax? What was the rationale behind that decision? Will you accept a pull request to implement that?
The problem: datatable.table_columns['purchasable']['filter']['values']
is {}
when I expect it to be {'Posts' => [['Post A', 1], ['Post B', 2]], 'Events' => [['Event A', 1], ['Event B', 2]]}
or something similar.
The values hash is hard coded, however, and makes me think that my statement above is a misunderstanding of what is going on. The hard coded hash is here:
If you look at similar cases surrounding that line, the values hash is generated dynamically rather than being static. So, this line might be the source of the issue. When I try to change the line to generate a hash like I've suggested above, I start running into other problems though.
I'm seeing this issue with the following set up:
The model:
class TokenTransaction < ActiveRecord::Base
belongs_to :purchasable, polymorphic: true
...
end
The datatable:
class Effective::Datatables::TokenTransactions < Effective::Datatable
datatable do
...
table_column :purchasable
...
end
def collection
TokenTransaction.all
end
end
I've got exactly one TokenTransaction record which has an associated purchasable object.
Hi,
Since this 0230a4c change, I noticed that the arrow is not correctly positioned – see per page number.
Removing max-width: 45px; fixes it for me.
Also, this line:
Adding a little bit of padding to the right make it better so as to make "Showing 1 to 1 of 1 entries" does not merge with the with "10 per page" part.
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 '."id" DESC NULLS LAST LIMIT 25 OFFSET 0' at line 1: SELECT inventories
.* FROM inventories
ORDER BY "inventories"."id" DESC NULLS LAST LIMIT 25 OFFSET 0
module Effective
module Datatables
class Inventories < Effective::Datatable
datatable do
default_order :id, :desc
table_column :id
table_column :folio
table_column :status
end
def collection
Inventory.all
end
end
end
end
Hi,
I would like to have change the DOM value for all tables. Specifically I want to have the length selector and export buttons at the bottom instead of on the top. I am currently doing this:
= render_datatable(@invoices_table, dom: "<'row'<'col-sm-12'tr>><'row'<'col-sm-6'i><'col-sm-6'p>><'row'<'col-sm-4'l><'col-sm-8'B>>")
But I have many tables, and so it would be better to centralise this value. I think having a config option on the initializer would be good.
Thanks for this beautiful plugin.
I added the bulk action implementation and when I see the table, the checkboxes are not visible.
It looks like the below css (in materialize.css) is making it invisble.
[type="checkbox"]:not(:checked), [type="checkbox"]:checked {
position: absolute;
left: -9999px;
visibility: hidden;
}
When I remove the position and visibility attributes, I can see the checkbox.
Am I missing anything?
Thanks!!!
Hi,
I noticed that the actions_col
are not present in the Show/Hide interface, but they do get collapsed, so there is not way to uncollapse them unless you click on the 'Show All button'.
I would suggest:
Also, is there a way to disable the responsive behavior globally, or per effective datatable?
I tried adding responsive: 1
but the column still gets to be hidden,
Hi,
If we'll keep the cursor in the search field in the data table, it is sending requests to server seamlessly on pressing/holding ALT key in the keyboard.
How to restrict/avoid this.
Thanks in advance.....
Hi,
In Mac OS you can click _CMD_ + A
to select all text on an input field. But when I do this on one of the text fields for filtering, nothing happens – the CMD keypress is ignored, and a 'A' character is added to the input.
CMD+A is useful when you want to clear the filter in a quick way, so I think the user should not be prevented form doing this.
I suspect EffectiveDatatables is capturing the relevant key events somehow.
Hi there! I am testing your gem out on my project, it looks quite interesting, but I've run into a couple of issues. If you don't mind I'll open them here in Github for your feedback.
The following line (and 129) is silently raising an error and returning 1:
I believe the cause may be an incompatible version of mysql2 gem.
For me this code returns an Array, therefore calling .values
raises an error.
>> collection_class.connection.execute("SELECT COUNT(*) FROM (#{collection_sql}) AS datatables_total_count").first
=> [111]
>> collection_class.connection.execute("SELECT COUNT(*) FROM (#{collection_sql}) AS datatables_total_count").first.values
!! #<NoMethodError: undefined method `values' for [111]:Array>
I'm wondering if this can be simplified by just calling collection.count
?
Thanks for reading this!
Hi,
This is fantastic library, I am big fan of this gem. Thanks for wonderful work done by you!
I am having 50,000 rows in my table, where I am using this gem. Everything is smoothly working, but **Search is taking too long _, some times we are getting _Server Time out error. How to improve search functionality.
Is there a better way to use search functionality ? or how to improve search functionality.
Kindly help me to overcome this.
Thanks in advance,
Mallikarjuna.
Hi,
So when I create a scope and display it on the view, there is a 'Reset button'. But is not working.
Perhaps its implementation was not finished?
When you click on it, it triggers a reset event on the form, but there no handler for that event defined anywhere, so nothing happens:
Hi, I'm using Bootstrap 4 and the datatables UI is broken. Is there any plan for Bootstrap 4 support?
Hi,
I am trying to have one of the tables default to have 5 rows. I tried to lengthMenu
but it doesn't seem to have an effect.
= render_datatable(@invoices_table, { "lengthMenu" => [ 5, 25, 50, 75, 100 ] })
Thoughts?
I'd like to render DataTable with my custom JS and HTML (would like to skip your proposed View).
My controller looks like this:
def index
#some code...
render json: Position::OutdoorDatatable.new(self) #this is not working at the moment
end
effective_datatables
file looks like this:
class Position::OutdoorDatatable < Effective::Datatable
datatable do
col :name
col :ptype, as: :jsonb
col :address,as: :jsonb
col :id
end
collection do
Position::Outdoor.all
end
end
and my position/outdoors/_index.html.erb
partial looks is this:
<div class="ibox">
<div class="ibox-content">
<table
id="outdoor_table"
data-source="<%= medium_position_outdoors_path(format: :json) %>"
data-user="<%= current_user.id %>"
data-create="<%= current_user.can?(:create, Position::Position) %>"
data-update="<%= current_user.can?(:update, Position::Position) %>"
data-destroy="<%= current_user.can?(:destroy, Position::Position) %>"
cellpadding="0"
cellspacing="0"
border="0"
class="display table table-striped table-bordered table-hover"
width="100%">
<thead>
<tr>
<th data-priority="1">Name</th>
<th data-priority="2">Type</th>
<th data-priority="3">Address</th>
</tr>
</thead>
<tfoot></tfoot>
</table>
</div>
</div>
<!-- some more code !-->
The table is initialized by this line in position/outdoors/index.js.coffee
$("#positions_table").html "<%=j render 'index' %>"
At the moment I'm getting an error:
ArgumentError (wrong number of arguments (given 1, expected 0)):
app/controllers/position/outdoors_controller.rb:11:in index
Is there a way for me to keep my views, JS and add just use server side part of your gem? I'd like to keep my index partial to be triggered and then in my JS I have ajax, which gets JSON from server.
Hello. I'm using this gem to write plugin in redmine. Unfortunately i can't put require in application.js( application.css). I'm importing assets with stylesheet_link_tag, javascript_include_tag. Is it possible to import effective_datables assets same way? Thank you for your attention!
Hi,
I have this filter:
filter :status, 'unarchived', as: :select, collection: [['Unarchived', 'unarchived'], ['Draft', 'draft'], ['Archived', 'archived'], ['Sent', 'sent'], ['Viewed', 'viewed'], ['Overdue', 'overdue']], label: false, include_blank: false
And this renders this:
Problems:
label: false
is ignored.unarchived
is not selected in the select
.include_blank
is also ignored.What am I doing wrong? 😅
Hi,
I am using a partial to display one of the columns. I need to have access to the attributes that were passed to the EffectiveDatatable, but I am not sure how to do it.
Example:
@members_table = OrganisationMembersDatatable.new(self, organisation_id: current_organisation.id)
In the partial I need to have access to that organisation_id
. This works fine when the table is first rendered, since the organisation_id parameter is available as part of the params
hash. But when performing a search on the column the params are empty, because – as I understand it – Effective Datatables now uses a cookie to store that info.
How do I get access to that cookie?
I tried this:
In the Effective::DatatablesController
I put a binding.pry to take a look at the params:
[2] pry(#<Effective::DatatablesController>)> params
=> <ActionController::Parameters {"draw"=>"3", "columns"=>{"0"=>{"data"=>"0", "name"=>"name", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"sad", "regex"=>"false"}, "visible"=>"true"}, "1"=>{"data"=>"1", "name"=>"tags", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "2"=>{"data"=>"2", "name"=>"_actions", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}}, "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0", "length"=>"25", "search"=>{"value"=>"", "regex"=>"false"}, "cookie"=>"074072723805", "locale"=>"en", "controller"=>"effective/datatables", "action"=>"show", "id"=>"organisation_members_datatable", "format"=>"json"} permitted: false>
I noticed that there is a "cookie"=>"074072723805"
parameter, but when I did cookies['074072723805']
it's nil.
So, in a view, how do I get access to the attributes that were passed to the EffectiveDatatable?
After updating the effective_datatables gem from version "2.6.11" to "2.12.0" the ajax requests for the datatables in our app are broken.
For a simple datatable such as:
# app/models/effective/datatables/users.rb
module Effective
module Datatables
class Users < Effective::Datatable
datatable do
table_column :email
table_column :last_name
table_column :first_name
...
actions_column
end
def collection
User.all
end
end
end
end
... the ajax request used to call something like:
localhost:3000/datatables/users.json
... but it now calls:
localhost:3000/datatables/effective%2Fdatatables%2Fusers.json
This does not work well with our webserver setup (Apache + Passenger) as the forward slashes (%2F) in the URL result in Apache returning a 404 page.
After a quick look at the commit history the issue is probably related to commit b55291a: Clean up classify.
Suggested solution: avoid using forward slashes in the ajax URLs.
Hi,
I have this code:
table_column :holder, filter: { as: :grouped_select, collection: Proc.new { holder_collection } } do
...
end
def holder_collection
{
'Members' => current_space.members.joins(:payments).map { |p| [ p.name, p.to_global_id.to_s ] },
'Suppliers' => current_space.suppliers.joins(:payments).map { |p| [ p.name, p.to_global_id.to_s ] }
}
end
But this fails with:
Grouped collection expecting a Hash {'Posts' => Post.all, 'Events' => Event.all} or a Hash {'Posts' => [['Post A', 1], ['Post B', 2]], 'Events' => [['Event A', 1], ['Event B', 2]]}
Notice that's using a :grouped_select. A :select works fine. In other words, :select can handle Procs, but :grouped_select can't.
I believe it should be supported, right?
One more question, do we really need to use a proc if we are going to have dynamic content (results of a query) or can we just use User.all (for example) without a Proc?
I suspect we need to use a Proc because this class is evaluated just once on code load, so we use a Proc to get up to date data on each request, but I wanted to confirm my understanding.
Hi,
I have got some complex filters in mind and I would like to create a partial and put a simple_form form there and use it as the filters of a datatable.
In other words, I would like a custom filter toolbar.
Is it possible?
As of 3.2.1+ effective_datatables is unable to find the datatable for me.
First load works. But reloading (filtering, refresh) gives:
DataTable error: unable to find datatable
Please refresh the page and try again
The url of the JSON request is: "/datatables/skype_users_datatable--40537094.json?locale=en"
Parameters: {"draw"=>"3", "columns"=>{"0"=>{"data"=>"0", "name"=>"display_name", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "1"=>{"data"=>"1", "name"=>"sign_in_address", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "2"=>{"data"=>"2", "name"=>"status", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "3"=>{"data"=>"3", "name"=>"phone", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "4"=>{"data"=>"4", "name"=>"office", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "5"=>{"data"=>"5", "name"=>"department", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "6"=>{"data"=>"6", "name"=>"_actions", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}}, "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0", "length"=>"25", "search"=>{"value"=>"", "regex"=>"false"}, "cookie"=>"-40537094", "locale"=>"en", "id"=>"skype_users_datatable--40537094"}
table:
How can I fetch grade's id only?
class BatchesDatatable < Effective::Datatable
datatable do
col :title
col :grades
actions_col
end
collection do
Batch.includes(:grades).all.order(created_at: 'DESC')
end
end
this is exactly what i was looking for, thank you!
Hi,
Started POST "/datatables/users_datatable-633246437562.json" for 79.75.59.52 at 2018-01-26 17:05:24 +0000
Processing by Effective::DatatablesController#show as JSON
Parameters: {"draw"=>"2", "columns"=>{"0"=>{"data"=>"0", "name"=>"email", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"gm", "regex"=>"false"}, "vis
ible"=>"true"}, "1"=>{"data"=>"1", "name"=>"name", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "2"=>{"data
"=>"2", "name"=>"eth_address", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "3"=>{"data"=>"3", "name"=>"kyc
", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "4"=>{"data"=>"4", "name"=>"whitelisted", "searchable"=>"tr
ue", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}, "5"=>{"data"=>"5", "name"=>"GCP", "searchable"=>"true", "orderable"=>"true", "s
earch"=>{"value"=>"", "regex"=>"false"}, "visible"=>"true"}}, "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0", "length"=>"25", "search"=>{"value"=>"", "rege
x"=>"false"}, "cookie"=>"633246437562", "id"=>"users_datatable-633246437562"}
Can't verify CSRF token authenticity.
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
I use Devise.
If current_user is admin (when admin attribute is true), I want to authorize the display of the Users datatables.
Within config/initializers/effective_datatables.rb
for auth:
config.authorization_method = Proc.new { |controller, action, resource| current_user.admin? }
Within app/datatables/users_datatable.rb
:
class UsersDatatable < Effective::Datatable
datatable do
col :email
col :name
col :eth_address
col :kyc
col :whitelisted
col :GCP
end
collection do
User.all
end
end
Within application.js
:
cat application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .
//= require effective_datatables
Within application.css.scss
:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*= require effective_datatables
*/
Any idea? @matt-riemer
Thanks!
Hello i have run into a issue while trying to use this gem with sqlite3, here is the framework trace:
SQLite3::SQLException: near "NULLS": syntax error: SELECT "rooms".* FROM "rooms" ORDER BY "rooms"."id" ASC NULLS LAST LIMIT 25 OFFSET 0
sqlite3 (1.3.11) lib/sqlite3/database.rb:91:in `initialize'
sqlite3 (1.3.11) lib/sqlite3/database.rb:91:in `new'
sqlite3 (1.3.11) lib/sqlite3/database.rb:91:in `prepare'
activerecord (4.2.4) lib/active_record/connection_adapters/sqlite3_adapter.rb:296:in `block in exec_query'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
activerecord (4.2.4) lib/active_record/connection_adapters/sqlite3_adapter.rb:293:in `exec_query'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/database_statements.rb:351:in `select'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all'
activerecord (4.2.4) lib/active_record/querying.rb:39:in `find_by_sql'
activerecord (4.2.4) lib/active_record/relation.rb:639:in `exec_queries'
activerecord (4.2.4) lib/active_record/relation.rb:515:in `load'
activerecord (4.2.4) lib/active_record/relation.rb:243:in `to_a'
activerecord (4.2.4) lib/active_record/relation/delegation.rb:132:in `method_missing'
activerecord (4.2.4) lib/active_record/relation/delegation.rb:99:in `method_missing'
effective_datatables (2.1.13) app/models/effective/effective_datatable/rendering.rb:106:in `arrayize'
effective_datatables (2.1.13) app/models/effective/effective_datatable/rendering.rb:51:in `table_data'
effective_datatables (2.1.13) app/models/effective/datatable.rb:72:in `to_json'
effective_datatables (2.1.13) app/views/effective/datatables/_datatable.html.haml:17:in `__home_diego__rvm_gems_ruby_______rent_gems_effective_datatables________app_views_effective_datatables__datatable_html_haml__786013744458836956_37199940'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:309:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:21:in `render'
actionview (4.2.4) lib/action_view/helpers/rendering_helper.rb:32:in `render'
haml (4.0.7) lib/haml/helpers/action_view_mods.rb:12:in `render_with_haml'
effective_datatables (2.1.13) app/helpers/effective_datatables_helper.rb:6:in `render_datatable'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.4) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.4) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.4) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.4) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (4.2.4) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/diego/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (4.2.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.4) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.4) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.4) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.4) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.4) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.4) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.4) lib/rails/engine.rb:518:in `call'
railties (4.2.4) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/home/diego/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/home/diego/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/home/diego/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Best regards! :)
Hey all,
As of effective_datatables 4.0+, this gem will be using Bootstrap4 instead of Bootstrap3 and Rails 5.1+ form_with
instead of simple_form.
The 4.x version of effective_datatables is intended to work alongside (the still very much WIP) effective_bootstrap gem.
The bootstrap3
branch, with its 3.x versions, will be maintained and will continue to work with Bootstrap3 & simple_form
Hi,
I have another interesting sample:
col :status, sql_column: 'something', sort: false, search: { as: :select, collection: [['collected', :collected], ['pending', :pending], ['failed', :failed]] } do |charge|
charge.status.humanize
end.search do |collection, term, column, sql_column|
case term
when 'collected'
collection.collected
when 'pending'
collection.pending
when 'failed'
collection.failed
end
end
The :status
column is not backed by a database column. It's an artificial value calculated on the model. There are also scopes for each of the possible values.
Normally I would get an array here instead of a collection. But on the search I wanted to be able to use an actual active record relation and not an array. I was getting an array, because the charge
doesn't have a column named status
(it does have that method though). I got it to give me a relation by adding a sql_column
parameter – but notice that the value is 'something', it's not used at all.
I was wondering if this is the best way to do this or you could point to me on a better path. I could be using a filter, but I really think it is better to put this in the column.
Hi,
This code does not fail:
table_column :something, filter: { :as => :select, :collection => Proc.new { raise StandardError.new('hi!') } }
It just gives you a table without the select filter for that particular column. No error.
This makes errors a little bit difficult to find and fix. It's probably some of the rescue
clauses on the code. I noticed that most of them are set to rescue all exceptions. Perhaps that could be changed to just rescue StandardErrors – or relevant exceptions for that code section.
It seems you have created great gem and I'd like to try it. I was wondering, if it would be possible to integrate Yet Another DataTables Column Filter (yadcf) with your gem?
In addition I'm interested, if your gem supports filtering / searching by JSONB column data? For example, in my Position
model I have JSONB column data
and I would like to search by values of ptype
inside it. I can access my data with something like this: Position.data->>'ptype'
Hi!
I noticed that when I change a filter and then wander to another page, and then I come back to the original page, the table will be set up with the changed filter. I would expect it to be pristine; without any filters.
Is there a way to configure this?
It is problematic in my case because one of the filters is a date.
filters do
filter :date, I18n.localize(Time.current, format: I18n.t('datepicker.dformat', default: '%d/%m/%Y')), as: :date_picker, label: false, parse: lambda { |term| Time.zone.parse(term).to_date }
end
So with this, the date will be initialised to today. Then the user can change it to some other day. When the user goes to another page, and then comes back, the datatable uses the second date, not the default one; but strangely the datepicker is initialised with the default one. It is very confusing.
Same thing happens with sorting, and column filters. I would prefer to have a pristine table every-time it is rendered.
Is it posible?
I have got this in my main.js file
$.extend( true, $.fn.dataTable.defaults, { destroy: true, stateSave: false } );
But doesn't seem to be a problem of stateSave. I am guessing this is saved in the cookie.
Thoughts?
Hello,
I was trying to perform search & sort on serialized column. The search works appropriate where as the sort gives an error indicating datatables#show (ArgumentError) "comparison of Array with Array failed
The column include the blank string. Is there anyway to solve this error?
Thanks in Advance!!!
I'd love to dig into this gem, however, I'd love to see a demo implementation somewhere. Is one available?
I have a nested resource:
resources :accounts do
resources :transactions
end
I created a datatable model for transactions, but couldn't figure out why the actions where not rendering any icons until I realized it must be the fact that the paths are nested. I worked around it by doing something like this:
actions_col do |tx|
link_to '<i class="glyphicon glyphicon-pencil"></i>'.html_safe, edit_account_transaction_path(tx.account_id, tx)
end
which works fine, but I wondered if there is some way to tell effective_datatables (or effective_resources?) that this is a nested resource so that it 'just works'.
If not, might be nice to have a mention in the docs.
class DiscountsDatatable < Effective::Datatable
datatable do
length 5
col :id
col :title
col :type
actions_col
end
collection do
Discount.all.order(created_at: :desc)
end
end
I recieve: length must be 10, 25, 50, 100, 250, 500, :all. The docs state we can specify the length to be 5 as well. length-link
First of all, thank you for this very useful gem.
Is there a way to save the state (filtering, pagination, sort order, ...) of the datatable between multiple requests?
Hi,
Awesome gem, thank for it.
I have a question regarding the filter. I have this code:
array_column :member, filter: { :as => :select, :collection => current_space.members } do |invoice|
link_to invoice.member.name, manager_accounting.member_path(current_space, invoice.member)
end
As you see, it uses a select
. But this list of members could be really big, so I would really like to use a :chosen
field – an autocomplete similar to select2. Normally I can create a chosen field with as: :chosen; I am using simple_forms.
I tried replacing the as: :select
with as: :chosen
, but it just doesn't output anything on the header. No error message, just an head row with just a label and no input field.
How can I do this?
I see the code that handles this is defined at https://github.com/code-and-effect/effective_datatables/blob/master/app/helpers/effective_datatables_private_helper.rb#L82
Maybe I could make a push request that adds a new input type. But maybe in the long term we should extract this so that it is more easily extended. I am thinking of something similar to how SimpleForm allows you to extend the custom input fields.
Hi Matt!
I've been testing effective_datatables with production data and found that the query made in total_records is quite slow for me, over 4 seconds in my case. There may be some optimization I can make in our db, but I believe it's fundamentally slow because the nested select is selecting all records and all columns in the table.
An example query like:
SELECT COUNT(*) FROM (SELECT ... WHERE (...)) AS datatables_total_count
This query takes about 4100ms.
If I remove the nested select, and perform the same query but just selecting a count:
SELECT COUNT(*) FROM ... WHERE (...)
Then the count query takes about 20ms.
Maybe we can improve total_records query to use activerecord .count
when possible, and fallback to the current query when not?
Do you think you could provide an example of when .count
does not work? If so maybe I could work on a solution.
Thanks!
Sheldon
Hi,
In the previous version I could set a custom width like this:
table_column :paid, label: 'Status', width: '70px'
But this doesn't work anymore. I get a wrong key error. How do I do this now?
first of all thanks for awesome gem 👍
I want to add greedy search in my current table and with it. i also want to add date range filter which is based on date-range picker
Thanks for this gem, it looks really great. Have a problem with 3.0 branch where master branch works ok. Using Rails 4.2.8 and ActiveRecord. Error when rendering view:
.../.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/effective_datatables-13f24c24b6b2/app/views/effective/datatables/_datatable.html.haml where line #10 raised:
no implicit conversion of nil into String
Perhaps I don't understand the new DSL. User has authorization, and I've even tried turning setting authorization to false.
Here is the model:
class SpeciesDatatable < Effective::Datatable
collection do
Species.all
end
datatable do
col :id
col :genus
col :species
end
end
This is a subset of the columns in the table. Using MySQL (in development) and table has no indexes other that primary key on ID.
View and Controller are as described in readme. Using the generated initializer Same error for render_simple_datatable(@datatable)
or render_datatable(@datatable)
I've tried adding
datatable do
order :id, :desc
....
but get the same error.
Hopefully this is helpful, sorry I'm reporting a problem with no suggested fix. Happy to provide more info. Best of luck on v3
The docs seem quite rails specific. Anyone know if this can be plugged into Sinatra or like frameworks?
thanks!
Hi,
Thanks for a great Gem
i am using rails 5 with turbolink ,
effective datatables is working fine initial page load but whenever page transition occur its lost datatables beauty. is there any work around
Hi!
I'm giving this another shot, because after some testing it appears like the only issue with mysql is the one I ran into earlier. :)
I'm trying to bundle this project, but I receive the following error when I run bundle install
:
Gem::InstallError: rack requires Ruby version >= 2.2.2.
An error occurred while installing rack (2.0.1), and Bundler cannot continue.
Make sure that `gem install rack -v '2.0.1'` succeeds before bundling.
I'm using ruby 2.1.0, as per the .ruby-version
file in the repo root.
I believe this issue here might be that the gemspec doesn't specify any gem versions, therefore my bundler is possibly bundling different versions than what you have. I can't easily fix this because I don't know what versions of these gems you are using. :S
Do you think you could update the gemspec with the correct gem versions? Thanks!
Hi,
I updated effective_datatables to 3.3.11 and my datatables stopped working. I took a look this repo to see the changes but master didn't have those new commits. So I dug in the local gem and I noticed that the last pull request (filters stuff) seem to be missing, and that's why my tables are failing.
3.3.11 is not pushed to master, but the release 3.3.11 is there: https://github.com/code-and-effect/effective_datatables/releases
So if I click on it, we can see the tree:
Which has diverged from master:
https://github.com/code-and-effect/effective_datatables/commits/master
Notice the commits "Version 3.3.10" in one tree and the other are different.
The commits on Jan 16, 2018 are missing on the currently released gem.
I guess you started working on new changes without pulling the latest master. Then hit release but the next version on your local (3.3.10) was already released and failed. So you incremented the version, commited and tried releasing again. The gem pushed, but the code didn't, because it conflicted with master. And that's how we got here :)
Hi,
So I have got an application that has the following authorisation roles:
And my application has to serve multiple clients. So each user has a role that is scoped to a particular client. Classic multi-tenant app.
I have this initialiser:
config.authorization_method = Proc.new { |controller, action, resource| datatable_authorization_method(controller, action, resource) }
And this on my application controller:
def datatable_authorization_method(controller, action, resource)
datatable = controller.instance_variable_get(:@datatable)
return true if datatable.blank? # We are in one of our own controllers; so permissions are handled in BaseController.
return true if datatable.attributes[:require_role].blank?
# We are in Effective::DatatablesController
case datatable.attributes[:require_role]
when :owner
return current_user.account_owner?(current_account)
when :admin
return current_user.account_admin?(current_account)
when :manager
return current_user.account_manager?(current_account)
when :member
return current_user.account_member?(current_account)
else
raise NotImplementedError.new
end
And I instantiate an effective datatable like this:
def index
@contracts_table = ContractsDatatable.new(self, account_id: current_account.id, require_role: :manager)
end
And it works fine, so far. But I think it is a little bit hacky to have that datatable = controller.instance_variable_get(:@datatable)
. I was wondering if the @datatable
could be one of the arguments that are passed to the authorization_method
. So that it would be like this:
config.authorization_method = Proc.new { |controller, action, resource, datatable| datatable_authorization_method(controller, action, resource, datatable) }
That way I can be confident that it will not break. What do you think? Or if you could suggest a different alternative.
Hi,
I am trying to implement a custom search method, but the collection I am getting in the search method is an array instead of a scope.
col :member_id, sort: false, label: 'Member', search: { as: :select, collection: members_collection } do |charge|
link_to charge.member.name, manager_accounting.member_path(current_space, charge.member)
end.search do |collection, term, column, sql_column|
collection.joins(:invoice).where(invoices: { member_id: term })
end
collection do
charges = current_space.charges.includes(:payment_method, :invoice, invoice: :member)
end
The collection
in the search
method holds an array of arrays. But what should be coming out of the collection block is a scope.
This is the type of the charges
variable in the collection block:
[2] pry(#<Effective::DatatableDslTool>)> charges.class
=> Charge::ActiveRecord_AssociationRelation
What am I doing wrong?
Hi,
I have this code on the initializer:
config.authorization_method = :datatable_authorization_method
And this in ApplicationController
def datatable_authorization_method(action, resource)
params[:attributes][:coworking_space_id] == current_user.coworking_space.id.to_s
end
But the method is being called without the two arguments, so I get wrong number of arguments (given 0, expected 2)
for that method.
Defining the method as def datatable_authorization_method
removes the error.
So perhaps there is a change to be done here:
https://github.com/code-and-effect/effective_datatables/blob/master/lib/effective_datatables.rb#L25
I am not using Cancan or Pundit.
bulk actions always calling show
action of the specified controller.
Example:
bulk_actions_column do bulk_action 'Approve all', bulk_approve_tags_path , data: { confirm: 'Approve all selected posts?' } end
If I click Approve all, I am getting request to tags_controller#show
action, not tags_controller#bulk_approve
action.
Routes file:
resources :tags do collection do post :bulk_approve end end
Am i doing wrong ?
Kindly let me know.
Not sure if this is the correct place to ask, but does this gem integrate well with the Editor extension of Datatables?
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.