Insérer des datagrids dans une application Ruby on Rails en quelques lignes de code est désormais possible.
Testez la démo de mon nouveau plugin :
2dcJqgrid.
Les datagrids sont basés sur un plugin jQuery et supportent les fonctionnalités suivantes :
- Ajax
- Pagination
- Tri
- Recherche
- Sélections multiples
- Master-Details
- Manipulation des données (création, édition et suppression)
- Et plus encore ...
Ajouter un commentaire
89 commentaires pour cet article
looks VERY nice - great work! I look forward to giving this a spin
Ecrit par de-railed le 14 avril 2009 02:44
Fabulous! I'm using it for work, and I am working on extending it right now.
I need it to display columns which are not ActiveRecord attributes, I don't see a way to do that with the plugin as it is.
blak3mill3r at gmail
Ecrit par robotmadness le 15 avril 2009 09:47
I have a patch which lets the datagrid show columns which are not AR attributes (they can be the return value of any method). Obviously sorting, editing, etc do not work on such a column. However, I found it useful, and it's a small & unobtrusive change.
If you're interested, send me an email: blak3mill3r 4T gmail D0T com
Ecrit par robotmadness le 15 avril 2009 10:14
Good job, man!
I was looking for months how to get a editable jqgrid with Rails.
I'd like to use your solution for editing stuff in a n:m relationship by using subgrids, e.g. flights having many passengers and passengers being booked on many flights.
How would this work with your plugin ?
And more general - how does further development of jqgrid relate with your plugin ? I guess you have to adopt any change into your plugin, as it resembles a kind of wrapper similar to jmaki, right ?
Regards and thanks again for your achievement
Peter
Ecrit par husky le 17 avril 2009 14:47
Hi guys,
Thanks for your comments!
robotmadness > I sent you an email but didn't get a response.
husky >
Subgrids were not yet implemented but I've been working on that this morning and it's now committed. So you can update your plugin and have a look at the demo application on GitHub.
The online demo has also been updated, have a look at the last example.
Yes, the Rails plugin acts as a wrapper around the Jqgrid plugin. I will follow his evolution and reflect interesting changes in my plugin. Follow the project on GitHub to be notified of any updates!
Cheers!
Ecrit par Anthony le 18 avril 2009 10:26
thanks for your quick response regarding subgrid! Checked it . The example works, but I can't enable add/edit/delete on subgrid. I guess you would have to code that in also ?
In the end I'd like to edit both users and pets and their relationships on one page.
Ecrit par husky le 20 avril 2009 13:07
It's great work ever!!
Ecrit par Ben le 21 avril 2009 02:30
This is beautiful work; solves lots of problems for me. Thank you. But... I'm having a problem that there must be a workaround for, but I can't figure it out. module JqgridJson can't handle columns with nil values or empty strings or even just all spaces. The line "value = elem.try(atr) if value.blank?" fails with "undefined method `try'". Is there a reasonable workaround?
Ecrit par RussK le 21 avril 2009 23:38
Thanks for your comments.
husky & RussK > I'll work on these issues as soon as possible and let you know when it's done.
Ecrit par Anthony le 22 avril 2009 07:13
Hi Anthony,
I was able to solve the problem I described. It looks like you may have added a try() method to your Object class, because otherwise there is no such method I could find. So in module JqgridJson I changed:
value = elem.try(atr) if value.blank?
to
value = "" if value.blank?
I don't know if this is the best solution, but it definitely works.
Ecrit par RussK le 22 avril 2009 20:20
Sorry for so many posts, but jqgrid and your plug-in are so useful! I have a question: is it possible to have a selection handler for a sub-grid? I can't even tell from the jqgrid documentation if it is. I tried the obvious thing of specifying another selection_handler in the subgrid hash, but it does not do anything.
Ecrit par RussK le 22 avril 2009 22:37
Looks really good--very impressed! Is it possible to use this plug-in with RESTful routes?
Ecrit par geetarista le 23 avril 2009 23:15
husky > I just added support for CRUD operations in subgrids. You can check it in the demo app on GitHub.
RussK > The try method is added to all ActiveRecord objects. So I presume you were getting this error because you were not working with AR objects. I applied a patch : value = elem.try(atr) if elem.respond_to?(:try) && value.blank?. Thanks.
RussK 2 > I also added support for direct selection in subgrids. Check the demo app on GitHub.
geetarista > Unfortunately, I don't think that it's possible at the moment. The Javascript plugin is only sending GET and POST requests at the moment. It will maybe be planned for a next release... and it will be a good thing.
Thanks for your comments!
The next thing I will work on is a jqgrid_generator. You will be able to use it like : generate scaffold user pseudo:string ....
Ecrit par Anthony le 26 avril 2009 13:49
I checked your CRUD for subgrids. First I had to add
protect_from_forgery :except => [:post_data, :post_pets_data] - easy.
As the action post_pets_data is missing, I added this:
def post_pets_data
if params[:oper] == "del"
Pet.find(params[:id]).destroy
else
pet_params = { :name => params[:name] }
if params[:id] == "_empty"
Pet.create(pet_params)
else
Pet.find(params[:id]).update_attributes(pet_params)
end
end
render :nothing => true
end
What's missing is insertion of the foreign key :user_id when creating a new pet. How would I do this ?
Ecrit par husky le 27 avril 2009 08:31
Oups, sorry! I forgot to send the parent id.
It's committed on GitHub, you can now get it using params[:parent_id].
Ecrit par Anthony le 28 avril 2009 20:51
I was glad to find out the plugin. However when I tried, it worked perfectly with your example. But when I tried using
User.find)by_sql("...") it does not work. I have a complicated query which needs to join 4 tables and I want to work with sql instead of the rails way find methods.
Do I have to use squirrel? I used rails 2.2.2.
Thank you very much for the plugin.
Kate
Ecrit par Kate le 08 mai 2009 12:57
The try method was added in Rails 2.3. Figured it out when I down graded to 2.2.2 to deploy on dreamhost. I added the following to get around it:
value = elem.send(atr.to_sym) if elem.respond_to?(atr) && value.blank?
Ecrit par tjsnell le 10 mai 2009 03:10
Hi,
Thanks for the plugin, it rocks !.
Would you please explain me if I can add a virtual attribute to the columns, or better yet, if I can save the value of a select field when reading from another model.
Example
player is fan of a Team X, and I would like to be able to select wich team from a table, and showing the name of the Team in the grid once edited.
I'm sorry if sound confuse, but i'm a native spanish speaker.
Gracias for your attention.
Ecrit par untaldouglas le 12 mai 2009 22:17
Hi,
Thanks for this plugin, I am working on an application having rails version 1.2.6, will this support me?
I am not able to install the plugin directly into my plugins folder(I am working on windows)
I download the plugin from github now let me know what name should I give to that plugin, and isit necessary to copy all js and css files into my public directory structure.
Any help from your side would be highly appreciable. thanks once again for writing this plugin
Regards
Puneet
Ecrit par puneet le 13 mai 2009 07:46
Hi I'm using the demo application created by you, after starting the server I got this error:
"NULL pointer given"
Please help me and give me some guidence of what's going wrong
Regards
Puneet
Ecrit par puneet le 13 mai 2009 10:07
Hi and thanks for your comments!
kate > You don't have to use squirrel. You can simply use basic ActiveRecord finders and will_paginate. It works very well even if you join models. What error do you get? Don't forget that if you don't use squirrel you have to replace total_entries by size when you call the to_jqgrid_json method.
tjsnell > Thanks for your patch! It's commited on GitHub!
untaldouglas > Look at the "Data manipulation with various input types" example in the live demo. You can set your team field as a selectbox. The options are set using :editoptions and you can of course replace the hardcoded values by data coming from your database.
puneet > The demo application will not work on Rails 1.2.6 because it has been generated using Rails 2.3. To install the plugin, you can just copy it in your app (we don't care about the name) and then copy all files from the plugin public folder to the public folder in your application (images, css & js). A lot of changes have been applied to Rails since 1.2.6 so the plugin will not work directly but you can edit the source code.
Ecrit par Anthony le 13 mai 2009 17:33
How do i display the error messages from the controller? Do I have to use the json object? If yes, can you please provide the syntax or process for this one? Thanks.
Ecrit par paul le 19 mai 2009 08:29
I've been playing around with it and found it very useful. I'm in the process of integrating it into my app. The only thing i missing is the ability to set the Height of the data grid. However the settings isn't supported by this plugin so i monkey patched it by adding the foll0wing to the jqgrid function
in the top:
options[:height] = "150" if options[:height].blank?
(150 seems to be the default according to the jqgrid docs)
added the followin to jqGrid section:
height: #{options[:height]},
it works like a charm,
Would you consider to add this to future versions of the plugin ?
Thanks for a great plugin
Ecrit par Zed le 28 mai 2009 22:03
Hello,
the plugin looks good, but it seems does not work with postgres! The plugin produce an sql query which raise an error.
"SELECT count(*) AS count_all FROM "users" ORDER BY id asc" raise the error. It would work fine without "ORDER BY id asc" .
Regards Christian
Ecrit par poolbar le 01 juin 2009 12:50
Hi guys and thanks for your comments!
paul > I added an option to display server side error messages (like ActiveRecord validation). Download the last version of the sample app and have a look at example 7.
Zed > Thanks for your contribution. Added and committed on GitHub!
poolbar > The plugin works mostly at client side so you can do what you want at server side. You can remove the order clause if you don't need it, you can use classic ActiveRecord finders instead of squirrel, etc. The only thing you have to do is return data formatted in JSON.
Ecrit par Anthony le 06 juin 2009 12:42
Can you please help me on how to integrate a datepicker in this plugin? Thank you very much
Ecrit par dominic le 08 juin 2009 05:51
dominic > I just added this functionality to the plugin. Check out the last version of the demo app on GitHub and have a look at example 9. When you click on a row and then on the lastname field, the datepicker appears.
The only thing you have to do is define a Javascript method (pickDates in this case) and set the inline_edit_handler option.
Ecrit par Anthony le 08 juin 2009 15:30
This is perfect! Thank you for this great plugin
Ecrit par dominic le 09 juin 2009 02:26
It can also be integrated in the add form right?
Ecrit par dominic le 09 juin 2009 06:15
Great Job! This is exactly what I need to make my application fly.
I hope this isn't a dumb question but is there a way to pass the selection_handler a value other than ID (like another field of the grid)? Thanks.
Ecrit par Perry le 10 juin 2009 06:38
Hi Anthony,
Can you please help me in sorting columns which are not AR attributes? I think this issue has been already raised by robotmadness.
"I have a patch which lets the datagrid show columns which are not AR attributes (they can be the return value of any method). Obviously sorting, editing, etc do not work on such a column. However, I found it useful, and it's a small & unobtrusive change.
If you're interested, send me an email: blak3mill3r 4T gmail D0T com "
Ecrit par paul le 11 juin 2009 03:21
Hi Anthony,
I have two questions today:
1: I would need an option to select multiple options from a drop-down list. Adding :multiple => "true" does not work:
{ :field => "members", :width => 140, :label => "Members", :editable => true, :edittype => "select", :multiple => "true",
:editoptions => { :data => [Resource.all, :id, :resourcename] } }
How can I pass this correctly to jqgrid ?
2. After selecting one or more options for on a selected row on a mastergrid, the subgrid for that row should reload and display details for the selected options. How can I trigger this behaviour ?
Ecrit par husky le 24 juin 2009 15:38
addendum to my last comment: I found out that jqgrid does support :multiple on input type select. But there was a bug which is fixed in 3.5 beta. I copied jqgrid 3.5 beta over my installation and it seems to work, but it spoiled your 2dcJqgrid installation. Do you have a timeline when you integrate 3.5 beta ?
The select gives me back a string of selected ids like "2,4,9".
How can I get instead an array [2,4,9] like RoR standard does when using e.g. options_from_collection_for_select ?
Ecrit par husky le 26 juin 2009 08:13
somehow talking to myself...
found out how to convert the string returned from a inputtype=select, :multiple=true -
childs = params[:childs].split(",").collect{ |s| s.to_i }
Then you can do this:
@parent.childs << childs.collect {|a| Child.find(a)}
giving you a mass-update of a N:M relationship between a mastergrid and a subgrid. So you can edit directly in one view which childs should belong to which parent.
Now a final step is missing - when rendering the parent table, the :childs column should show which children had been selected previously.
For one row the code would be
@parent = Parent.find(params[:id])
@selected_childs = @parent.childs.collect {|a| a.id}
But how do I integrate 1. getting the selected childs for all columns with
2. rendering the json output for the parent grid ?
Ecrit par husky le 26 juin 2009 15:32
Hi,
I get a 'NoMethodError: undefined method 'total_entries' for Array'. I installed squirrel as described in the doc but still I get this error!
What am I doing wrong?
Am using rails - 2.3.2
regds,
mano
Ecrit par mano le 26 juin 2009 17:38
When I tried the football players example given, I get the following error:
ActiveRecord::StatementInvalid (PGError: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
: SELECT count(*) AS count_all FROM "users" ORDER BY id asc ):
app/controllers/users_controller.rb:5:in `index'
If I comment out 'order_by "#{...."' call the grid displays. Of course the sorting does not work.
Hope this helps in solving the problem!
regds,
mano
Ecrit par mano le 26 juin 2009 18:28
Hi Anthony,
I have found a possible bug with master/detail:
when selecting a row which does not have any detail, the detail grid does not shrink to zero rows, but keeps on displaying the results of a previously selected row.
I double checked this by deleting the pet of player with id=2 in your demo app. If you click onto another row and then back to player #2, you still see the pets of the other player.
Ecrit par husky le 02 juillet 2009 15:58
great job!! this is what i looking for...
anyway, actually im looking for plugin like this but for PHP. do you make it?
Ecrit par hammudi le 03 juillet 2009 08:00
This is perfect - but I'm trying to use it with jRails and the two do not seem to work together. the jqGrid comes up, but it won't pull in data, even though it's calling the Rails functions and JSON is being sent - it won't populate. Is jRails' handling of AJAX interfering with jqGrid?
Ecrit par msmiller le 07 juillet 2009 23:31
Yup ... it's ajaxSend in jrails.js, it's not accepting "application/json" headers which jqGrid, I guess, expects. Just add that in and it seems to work fine.
Ecrit par msmiller le 08 juillet 2009 02:53
Hi i have installed Rails 2.1.2. will this plugin work for rails 2.1.2?. because when i run the application the controll goes to plugin and it load the 2dc_jqgrid. but when i execute the application from browser, it throws
undefined method `jqgrid' for #<ActionView::Base:0x72ab71c> error.
Can you please help me in this? i don't know why its throwing this error
Thanks,
Bala.
Ecrit par Bala le 08 juillet 2009 05:17
Hi guys,
Sorry, I don't have a lot of time at the moment to answer your questions.
I'll reply as soon as possible.
I created a Google group for the plugin, it's maybe easier to use it for your questions : http://groups.google.com/group/2dcjqgrid
Thanks for your interest!
Ecrit par Anthony le 11 juillet 2009 09:52
For the SQL Server adapter on Windows, you have to comment the order by clause in the controller (It does not provide valide TSQL for SQL Server). After this small modification, it works like a charm !
Ecrit par minikermit le 12 juillet 2009 20:14
i have test this on an iphone, there are several problems and it does work well. moslty its with the ajax implementation and the popup pieces. The iphone likes to post every thing so the searchs erc need to be triggered on a loss of focus from the search boxes or handled in a diffrenet mannor all together.
nice work but i think it needs more before i really used it in a production system
Ecrit par ash le 06 août 2009 13:47
Hi,
I am using firefox 2.0.0.8 and in that i am not able to see your examples in link so can you say me whats problem?
Ecrit par renuka le 10 août 2009 06:34
When is it possible to incorporate with jqGrid's cellEdit capability?
Ecrit par Qingfeng Cai le 11 août 2009 14:22
I really like the grid but I need to find out if there is a complete documentation of it. I need to know if there is a way to get the object you had just clicked and use it on a URL to show the complete contents of the row
any help would be appreciated
Ecrit par JADE le 16 août 2009 21:45
I am using postgres and the query below does not work, SQLite does not care about the Order by sintaxis in a count statement but Postgres and MS-SQL throw error messages when used, maybe is you point me on the right direction on where to change this, I will make the change myself. the grid looksGREAT!!! but needS this little improvement for more robust databases.
SELECT count(*) AS count_all FROM "countries" ORDER BY id asc
also I found that text and icons on the footer of the grid were not being displayed properly or where not been shown completely, I changed the HEIGHT parameter to 45px instead of 25px in the following class
.ui-jqgrid .ui-jqgrid-pager (the CSS file name where the class is contained is PUBLIC\JQGRID\ui.jqgrid.css)
Ecrit par JORGE CEA le 17 août 2009 19:41
This looks promising but I've run into a problem when using a model that is based on a Structure, rather than a simple SQL query. (Getting unknown 'attribute errors' in the to_jqgrid_json method - it seems to expect a specific fomat/structure that a Structure based result set does not provide.
I looked at the code and already tried remapping/reformatting my result set, but I think there are some dependencies here that are beyond my ken - so I'm not sure how to fix this, but I do have a sample app that demonstrates the problem that I can upload if you like. Just let me know.
Ecrit par BrendanC le 20 août 2009 08:53
Could someone post how to move the query into the model using the demo page code as an example? I'm pretty new to rails and I'm having a hard time figuring out how to best pass the arguments and return them. TIA
Ecrit par intensity le 21 août 2009 05:54
Hi,
I'm on holidays until end of August (no internet access).
I'll check your messages at that time.
Cheers
Ecrit par Anthony le 22 août 2009 09:12
Great Job! I've been using the jQuery datagrid for several weeks with no problems.
I even have a page with two grids on the same page.
Support Question:
Is there plans for a support forum?
Grid Question:
How can I get a selected row on one grid to highlight similar rows of the other grid?
Thanks again.
JohnM
Ecrit par JohnM le 27 août 2009 14:52
Hello and congratulations on the master detail grid, As an evaluator I have done extensive research for about a year across multiple programing tools/languages in search for a data grid that has these options, though there are many out there this looks very clean and the search option is a bonus. Two questions come to mind, one "data manipulation" do you have an option to manipulate data inside the grid ? as in a spreadsheet ? not a separate window. Two how do you envision this data grid working on an internationalized project? i.e. is it internationalization ready ?
Thank you for your contribution,
DDT
Ecrit par ddt3 le 03 septembre 2009 14:41
I have a couple of bug fixes for you, including the pluggin not always returning the correct number of total pages, and returning malformed json data when there is no rows returned. I also added an feature to auto adjust the height to the height of all the rows. If you're interested let me know:
s.sadowski at gmail
Also, thanks for the great work!
Ecrit par Steve le 08 septembre 2009 18:54
Hi there,
I've seen several people comment on the "order by" problem in postgres? I'm not sure if I'm savvy enough to find the proper fix, but was wondering if someone else had come across a way to make the ordering work properly. For reference I'm referring to this comment...
the plugin looks good, but it seems does not work with postgres! The plugin produce an sql query which raise an error.
"SELECT count(*) AS count_all FROM "users" ORDER BY id asc" raise the error. It would work fine without "ORDER BY id asc" .
I removed the ORDER BY, but the sorting doesn't work. I will dig into it and if I find a fix I'll let everyone know, but if someone has already figured it out I would love to hear.
GREAT PLUGIN BTW - I LOVE IT's SIMPLICITY.
Chris
Ecrit par Postgres fix?? le 11 septembre 2009 17:26
Greetings. I wrote a simple app that I plan to use as part of a
charity project. The app basically displays a nice table and enables
users to maintain the data. I used a basic rails scaffold. I also
used restful_authentication and stayed RESTful throughout. Now it all
works the way that I want.
It struck me that users would want to sort the data columns. Jquery seems
like a good fit for that. At the same time, I already wrote the logic
for CRUD actions. I also already took care of adding [RESTful] CRUD
links for each table row, depending on user role.
So here's the question: Is there a painless way to drop in JQuery for
just the Index action that lets me add a column for the CRUD links?
Thanks.
Ecrit par me le 17 septembre 2009 19:26
Hi,
This works really well, I love these tables, but I ran into a very fundamental issue....
Adding double quotes to a value breaks the whole thing, editing with the inline features!
I thought it was an error in my application, but I just tried again using the sample app:
-> going to example "13) Form Improvements"
-> click on a name
-> update the name with a word in quotes i.e: momo "here is the bug"
the value gets updated in the database, but the grid cann't display it afterwards, as the JSON response has too many quotes, it just displays a blank list, and a javascript error....
maybe we should do something like a javascript escape, replace with HTML entities, or disalow the quotes on user type ? what do you think ?
regards
Ecrit par jujudellago le 21 septembre 2009 16:32
just left my computer a while and the answer came easily..... I just had to modify the JSON response generated by the plugin.
in lib/2dc_jqgrid.rb
I added the rails javascript helpers, line 355
module JqgridJson
include ActionView::Helpers::JavaScriptHelper
so that in line 366 I could use the "escape_javascript"
json << %Q("#{escape_javascript(value.to_s)}",)
and now I can use the double quotes in the tables.
cheers
Ecrit par jujudellago le 21 septembre 2009 18:49
Hi,
I am trying to implement your plugin, but when I see the output in the browser I found something like this: http://twitpic.com/ix3va
There is no data I can see inside the grid..
Any help would be highly appreciable
Thanks
Puneet
Ecrit par puneetitengineer@gmail.com le 24 septembre 2009 07:26
This is regarding my previous comment, I did few changes with my controller's method and now everything is working fine.. thanks for posting this article..
Cheers
Puneet
Ecrit par puneet le 25 septembre 2009 06:12
Nice! This plugin is saving me a lot of ExtJS + Rails headaches. Thanks!
A small modification I did for a project (hope is useful to someone else too): Formatters.
In the main module file, under the get_attributes method, I've added a new elsif, for those times when you need to use formatters with formatoptions (e.g. custom links) in a column:
column.except(:field, :label).each do |couple|
if couple[0] == :editoptions
options << "editoptions:#{get_sub_options(couple[1])},"
elsif couple[0] == :formoptions
options << "formoptions:#{get_sub_options(couple[1])},"
#New code
elsif couple[0] == :formatoptions
options << "formatoptions:#{get_sub_options(couple[1])},"
#End of new code
elsif couple[0] == :searchoptions
options << "searchoptions:#{get_sub_options(couple[1])},"
...
I used for a "showLink" formatter. Worked as expected.
Ecrit par Sachi le 26 septembre 2009 21:39
hi i want to how i can to do number_to_currency in my query or in my view i need a help....
Ecrit par KuRkO le 28 septembre 2009 16:21
To Kurko (and anybody else who may need this):
Check this link: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter
You can declare your own formatter per column (using formatoptions...though YOU MAY NEED TO ADD A LITTLE CODE LIKE I MENTIONED IN MY PREVIOUS POSTING). E.g:
{ :field => "item_cost", :label => "Ordered",:width=>"100",:formatter=>"currency",:formatoptions=>{:decimalSeparator=>".", :thousandsSeparator=> ",", :decimalPlaces=> "2",:prefix=>"US$"},:align=> "right",:search=>false}
Alternatively, you can make the formatoption part global and modify the "locale" file (in the public/jqgrid/js/il8n directory) instead (You should understand once you locate the file). Then in your jqgrid column declaration, just use:
{ :field => "item_cost", :label => "Ordered",:width=>"100",:formatter=>"currency",:align=> "right",:search=>false},
Ecrit par Sachi le 02 octobre 2009 01:02
Thx Sachi for your help i love this plugin now jeje thx very much its 100% functional... thx
Ecrit par KuRkO le 05 octobre 2009 14:29
Ok i believe that this answer is very importat... HOW CAN I TO DEFINE THE GRID´S SIZE??? Height and Width... Of course for every Grid that i used in my application thx... if it could be make....
Ecrit par KuRkO le 07 octobre 2009 15:08
Hi KuRkO,
In the options of your grid, you can add this :
:height => 500, :autowidth => true
If autowidth is set to true, the grid width will be automatically set to the width of his container. So for example, you can encapsulate the grid in a DIV with a width of 100% or 400px or, ...
Ecrit par Anthony le 08 octobre 2009 20:25
great work! thank you so much for the plug-in, and thanks to the jqgrid author,too. I was able to follow your instructions and read your plug-in code to get it on my page, reading my data, changing the size, etc.
However, I find a couple of glitches, anyone else? I can post specifics if needed - it could just be my system. For one, sometimes clicking on the next page icon, the plug-in doesn't go to the next page and won't display the last records (that is says that it has). If others are seeing this, I'll get details on the problem. for me.
Ecrit par billspat le 23 octobre 2009 16:58
Hi..
In order to make the plugin works on postgres, you must change just one line on squirrel plugin. The problem is asociated with the following message error (a really headache):
ActiveRecord::StatementInvalid (PGError: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function
: SELECT count(*) AS count_all FROM "users" ORDER BY id asc ):
app/controllers/users_controller.rb:5:in `index'
Ok, open squirrel.rb file, seek 147 line and add the followin line:
conditions.delete(:order)
I mean, the function paginate_result_set must be:
def paginate_result_set set, conditions
limit = conditions.delete(:limit)
offset = conditions.delete(:offset)
class << set
attr_reader :pages
attr_reader :total_results
end
conditions.delete(:order) #LOOK AT HERE!!!!!!!!!!!!!!!!!!!!!
total_results = model.count(conditions)
set.instance_variable_set("@pages",
Paginator.new( :count => total_results,
:limit => limit,
:offset => offset) )
set.instance_variable_set("@total_results", total_results)
set.extend( Squirrel::WillPagination )
end
Hope this helps!!..
Ecrit par FIXED TO POSTGRES BY ALFREDO RICO FROM VENEZUELA le 05 novembre 2009 04:10
awesome plugin! thanks a lot.
Using the latest version of the plugin from Ahe I am experiencing two strange behaviors:
First, after performing a search and clearing the value (form field in table header) again the _search is set to false but my search param (such as params[:name]='xyz') is still set. This leads to the unfortunate situation that a second search in another column is limited to the previous one as well.
Any ideas on that?
Second, despite copying the code of the demo I won't get any select menus for the table header search fields. I set:
{ ..... , :edittype => "select",
:editoptions => { :value => [["","All"],["admin","admin"], ["player", "player"], ["defender","defender"]] } }
What am I missing here?
Besides that I would have be interested if the following features are already supported:
advanced_search
custom_formatter show_link with individually defined urls
excel export (or a way to get information of displayed columns after they have been modified through show,hide columns in the column manager, back into rails to exprot it from there)
Thanks a lot and many thanks again!
Ecrit par pheg le 06 novembre 2009 08:24
ALFREDO > Thanks for your work, I'll try to integrate it ASAP.
pheg > I commited a new version today, I think it should solve your issues.
Thanks!
Ecrit par Anthony le 06 novembre 2009 14:08
Thank you so much!
Though the :edittype => select thingy is still not working the search is working fine again - and that's by far the more improtant issue.
Thanks for the swift action!
Ecrit par Pheg le 06 novembre 2009 19:26
Hi people, congratulations this is an amazing plug-in.
I have a really newbie question, I'd like to know how to get the selected rows in my controller. I mean, I have the grid into a form, and when form is submited I'd like to get the selected ids. I really appreciate your help. Thanks.
Ecrit par eisen le 20 novembre 2009 14:03
Hi there - just attempted to implement this plugin, but I am getting error:
"undefined local variable or method `jqgrid_stylesheets' for #<ActionView::Base:0x480f774>"
is there a require statement necessary in environment.rb?
not sure what I'm doing wrong.... thanks for any help; I've been looking for this exact functionality for months!! :))
malokt@gmail.com
Ecrit par maloKT le 25 novembre 2009 01:17
Bonjour,
J4aimerai exporter mon tableau en EXcel.
Y a t'il un moyen d'ajouter cette fonctionnalités?
Ecrit par mazraelle le 25 novembre 2009 15:08
i've been trying to get this to work for a while. I can't even get the first example on the demo page to work. It just doesn't seem to want to read the JSON data.....
Ecrit par MikeP le 09 décembre 2009 21:29
Hi everybody,
Thanks for the great tutorial! I got it to work nicely in the index view just as you described it.
However I have a hard time getting it to work in the show view of another model.
I am trying to show the table of products in the category/show.html.erb
I guess it is a simple find problem, but being quite new to rails and a total ajax beginner I can't seem to figure it out by myself...
categories_controller:
def show
products = @category.products.find(:all) do #, :conditions => ['online = ? and category_id IN (?)', true, @category.subtree_ids]) do
if params[:_search] == true
productname =~ "%#{params[:productname]}%" if params[:productname].present?
vendorname =~ "%#{params[:vendorname]}%" if params[:vendorname].present?
usd_price =~ "%#{params[:usd_price]}%" if params[:usd_price].present?
end
paginate :page => params[:page], :per_page => params[:rows]
order_by "#{params[:sidx]} #{params[:sord]}"
end
respond_to do |format|
format.html # show.html.erb
format.json { render :json => products.to_jqgrid_json([:id,:productname,:vendorname,:usd_price],
params[:page], params[:rows], products.total_entries) }
end
end
in (categories)/show.html.erb:
...
<%= jqgrid(@category.name, "products", "/products",
[
{ :field => "id", :label => "ID", :width => 75, :resizable => false },
{ :field => "productname", :label => "Name" },
{ :field => "vendorname", :label => "Vendor" },
{ :field => "usd_price", :label => "$" }
]
) %>
...
I'ld appreciate any input if anyone has an idea what I am doing wrong!
Thanks,
Val
Ecrit par val le 16 décembre 2009 11:17
This is really a good plugin, made my work really easy.
But im facing a problem, if my record is having a comma,colon or semi colon in the record then it doesnt display any record.
Plz suggest
Thanks
Ecrit par Priya le 23 décembre 2009 10:59
@Priya
I think you need to escape those special characters. But is this really a problem with semicolon, comma and colon?
I had similar issue when the grid was not showing some pages. It was due to the double quotes in the json response, so I escaped double quotes and it worked for me.
Try this:
In to_jqgrid_json method,
below this line:
value = get_atr_value(elem, atr, couples)
add this:
value = value.is_a?(String) ? value.gsub(/"/, '\"') : value
Ecrit par gouravtiwari21 le 07 janvier 2010 03:49
Upon clicking on a row in the table I would like to populate a form for editing, does anyone have example code they could share to demonstrate this? Using the modal edit function is not an option due to the layout of my application.
Thanks!
Ecrit par Jayoshi le 10 janvier 2010 21:28
Can't seem to use this feature to displat the toolbar when the grid displays: toolbar:[true,"both"]
Any ideas?
Ecrit par Pinnacle le 14 janvier 2010 22:35
Tried using it with rails 2.3.4 and jrails 0.4.0.
So far can't get the grid to show up properly using the supplied CSS files. The grid title area's height is too large - takes 300 px at least. looks very odd.
Upon loading the supplied CSS in my application, Firebug reports a bunch of CSS errors.
Tried to build a custom jquery CSS for this with Jquery theme roller, but their current version is 1.7.2 and when applied it doesn't look correct.
Ecrit par David Ben Yosef le 22 janvier 2010 17:26
Hi all,
I have a doubt. I don't know if I'm doing something wrong or I have found a bug.
I have added the grid with a Detail grid, but if I set the Master grid :inline_edit => true, when I select any row, it doesn't load the info in the Details list.
I have checked the generated source code and the onSelectRow function is created, but it doesn't do anything.
Any suggestion?
Thanks in advance
Lexos
Ecrit par Lexor le 27 janvier 2010 16:59
Hi all,
I have fixed the error with the Master-Details and inline_edit issue.
I have added below code:
jQuery('##{id}').restoreRow(lastsel);
jQuery('##{id}').editRow(ids, true);
lastsel=ids;
after the If statement of masterdetails section in 2dc_jqgrid.rb file.
Best Regards
Lexor
Ecrit par Lexor le 28 janvier 2010 14:49
I tried to use inline_edit_handler and attached a method "handleInline" to it. However, it doesn't seem to work. The reason is the handler should be within the "jquery(document).ready(function()) and not outside. Are you sure "inline_edit_handler" works?
Ecrit par Raveendran V le 10 février 2010 15:45
This is terrific !
To make it quickly usable for the newbies, could you please also add the dependency requirements and installation instructions for Jruby on Windows users.executed the install command (script\plugin ...) did not succeed.
Ecrit par Thanks le 19 février 2010 22:38
I believe I miss something, but someone can explain me when in the index view I change the order of the fields, the view only change the header but no the content.
For example in 1)simple screnn I moved
<%= jqgrid("Football Players", "players", "/users",
[
{ :field => "id", :label => "ID", :width => 35, :resizable => false },
{ :field => "role", :label => "Role" },
{ :field => "pseudo", :label => "Pseudo" },
{ :field => "firstname", :label => "Firstname" },
{ :field => "lastname", :label => "Lastname" },
{ :field => "email", :label => "Email" }
]
the role field to the second column. However the role heading is the one that got moved but the content no.
How can I move the content as well
Thanks for your help
Ecrit par omar le 25 février 2010 09:56
Forget my previous comment. I solve the problem. If any one is a newbie as I am you need to change the order also in the controller action in the render:json statement
Ecrit par omar le 01 mars 2010 07:57
Has anyone been able to use the setucolumns to work?
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:show_hide_columns#calling_convention
newbie
Ecrit par dripjax le 08 mars 2010 19:01
Thanks for the plugin this is so sweet. Nevermind my newbie question, just added it to the 2dc_jgrid.rb and boom.
Ecrit par dripjax le 08 mars 2010 23:29