Add jQuery datagrids to your Ruby on Rails applications



Written by Anthony Heukmes on Mon Apr 13 14:53:33 UTC 2009

92 comments



It's now possible to add jQuery datagrids to your Ruby on Rails applications with just a few lines of code.

Have a look at the demo application of my new plugin : 2dcJqgrid.

Datagrids are based on a jQuery plugin and support the following features :

- Ajax-enabled
- Pagination
- Sorting
- Filters
- Multiple selections
- Master-Details
- Data manipulation (create, edit, delete)
- And more ...
Bookmark and Share

Add a comment



92 comments for this article



looks VERY nice - great work! I look forward to giving this a spin


Written by de-railed on Tue Apr 14 02:44:11 UTC 2009

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


Written by robotmadness on Wed Apr 15 09:47:39 UTC 2009

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


Written by robotmadness on Wed Apr 15 10:14:50 UTC 2009

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


Written by husky on Fri Apr 17 14:47:01 UTC 2009

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!


Written by Anthony on Sat Apr 18 10:26:17 UTC 2009

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.


Written by husky on Mon Apr 20 13:07:02 UTC 2009

It's great work ever!!


Written by Ben on Tue Apr 21 02:30:43 UTC 2009

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?


Written by RussK on Tue Apr 21 23:38:37 UTC 2009

Thanks for your comments.

husky & RussK > I'll work on these issues as soon as possible and let you know when it's done.


Written by Anthony on Wed Apr 22 07:13:53 UTC 2009

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.


Written by RussK on Wed Apr 22 20:20:18 UTC 2009

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.


Written by RussK on Wed Apr 22 22:37:44 UTC 2009

Looks really good--very impressed! Is it possible to use this plug-in with RESTful routes?


Written by geetarista on Thu Apr 23 23:15:20 UTC 2009

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 ....


Written by Anthony on Sun Apr 26 13:49:56 UTC 2009

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 ?


Written by husky on Mon Apr 27 08:31:43 UTC 2009

Oups, sorry! I forgot to send the parent id.
It's committed on GitHub, you can now get it using params[:parent_id].


Written by Anthony on Tue Apr 28 20:51:19 UTC 2009

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


Written by Kate on Fri May 08 12:57:13 UTC 2009

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?


Written by tjsnell on Sun May 10 03:10:26 UTC 2009

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.


Written by untaldouglas on Tue May 12 22:17:39 UTC 2009

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


Written by puneet on Wed May 13 07:46:06 UTC 2009

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


Written by puneet on Wed May 13 10:07:39 UTC 2009

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.


Written by Anthony on Wed May 13 17:33:24 UTC 2009

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.


Written by paul on Tue May 19 08:29:35 UTC 2009

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



Written by Zed on Thu May 28 22:03:51 UTC 2009

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


Written by poolbar on Mon Jun 01 12:50:33 UTC 2009

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.


Written by Anthony on Sat Jun 06 12:42:22 UTC 2009

Can you please help me on how to integrate a datepicker in this plugin? Thank you very much


Written by dominic on Mon Jun 08 05:51:22 UTC 2009

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.


Written by Anthony on Mon Jun 08 15:30:09 UTC 2009

This is perfect! Thank you for this great plugin


Written by dominic on Tue Jun 09 02:26:09 UTC 2009

It can also be integrated in the add form right?


Written by dominic on Tue Jun 09 06:15:46 UTC 2009

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.


Written by Perry on Wed Jun 10 06:38:24 UTC 2009

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 "


Written by paul on Thu Jun 11 03:21:02 UTC 2009

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 ?


Written by husky on Wed Jun 24 15:38:37 UTC 2009

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 ?


Written by husky on Fri Jun 26 08:13:51 UTC 2009

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 ?


Written by husky on Fri Jun 26 15:32:53 UTC 2009

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


Written by mano on Fri Jun 26 17:38:01 UTC 2009

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


Written by mano on Fri Jun 26 18:28:41 UTC 2009

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.


Written by husky on Thu Jul 02 15:58:49 UTC 2009

great job!! this is what i looking for...
anyway, actually im looking for plugin like this but for PHP. do you make it?


Written by hammudi on Fri Jul 03 08:00:35 UTC 2009

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?


Written by msmiller on Tue Jul 07 23:31:15 UTC 2009

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.


Written by msmiller on Wed Jul 08 02:53:27 UTC 2009

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.


Written by Bala on Wed Jul 08 05:17:40 UTC 2009

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!


Written by Anthony on Sat Jul 11 09:52:01 UTC 2009

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 !


Written by minikermit on Sun Jul 12 20:14:32 UTC 2009

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


Written by ash on Thu Aug 06 13:47:07 UTC 2009

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?


Written by renuka on Mon Aug 10 06:34:56 UTC 2009

When is it possible to incorporate with jqGrid's cellEdit capability?


Written by Qingfeng Cai on Tue Aug 11 14:22:10 UTC 2009

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


Written by JADE on Sun Aug 16 21:45:26 UTC 2009

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)



Written by JORGE CEA on Mon Aug 17 19:41:50 UTC 2009

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.


Written by BrendanC on Thu Aug 20 08:53:51 UTC 2009

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


Written by intensity on Fri Aug 21 05:54:42 UTC 2009

Hi,

I'm on holidays until end of August (no internet access).

I'll check your messages at that time.

Cheers


Written by Anthony on Sat Aug 22 09:12:01 UTC 2009

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


Written by JohnM on Thu Aug 27 14:52:48 UTC 2009

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


Written by ddt3 on Thu Sep 03 14:41:34 UTC 2009

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!


Written by Steve on Tue Sep 08 18:54:53 UTC 2009

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


Written by Postgres fix?? on Fri Sep 11 17:26:16 UTC 2009

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.


Written by me on Thu Sep 17 19:26:53 UTC 2009

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





Written by jujudellago on Mon Sep 21 16:32:56 UTC 2009

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


Written by jujudellago on Mon Sep 21 18:49:17 UTC 2009

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


Written by puneetitengineer@gmail.com on Thu Sep 24 07:26:00 UTC 2009

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


Written by puneet on Fri Sep 25 06:12:59 UTC 2009

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.


Written by Sachi on Sat Sep 26 21:39:50 UTC 2009

hi i want to how i can to do number_to_currency in my query or in my view i need a help....


Written by KuRkO on Mon Sep 28 16:21:05 UTC 2009

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},


Written by Sachi on Fri Oct 02 01:02:14 UTC 2009

Thx Sachi for your help i love this plugin now jeje thx very much its 100% functional... thx


Written by KuRkO on Mon Oct 05 14:29:03 UTC 2009

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....


Written by KuRkO on Wed Oct 07 15:08:17 UTC 2009

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, ...


Written by Anthony on Thu Oct 08 20:25:40 UTC 2009

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.


Written by billspat on Fri Oct 23 16:58:26 UTC 2009

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!!..



Written by FIXED TO POSTGRES BY ALFREDO RICO FROM VENEZUELA on Thu Nov 05 04:10:08 UTC 2009

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!


Written by pheg on Fri Nov 06 08:24:28 UTC 2009

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!


Written by Anthony on Fri Nov 06 14:08:23 UTC 2009

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!


Written by Pheg on Fri Nov 06 19:26:32 UTC 2009

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.


Written by eisen on Fri Nov 20 14:03:10 UTC 2009

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


Written by maloKT on Wed Nov 25 01:17:58 UTC 2009

Bonjour,
J4aimerai exporter mon tableau en EXcel.
Y a t'il un moyen d'ajouter cette fonctionnalités?


Written by mazraelle on Wed Nov 25 15:08:35 UTC 2009

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.....


Written by MikeP on Wed Dec 09 21:29:17 UTC 2009

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


Written by val on Wed Dec 16 11:17:40 UTC 2009

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


Written by Priya on Wed Dec 23 10:59:59 UTC 2009

@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


Written by gouravtiwari21 on Thu Jan 07 03:49:37 UTC 2010

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!


Written by Jayoshi on Sun Jan 10 21:28:46 UTC 2010

Can't seem to use this feature to displat the toolbar when the grid displays: toolbar:[true,"both"]

Any ideas?


Written by Pinnacle on Thu Jan 14 22:35:56 UTC 2010

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.





Written by David Ben Yosef on Fri Jan 22 17:26:23 UTC 2010

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


Written by Lexor on Wed Jan 27 16:59:09 UTC 2010

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


Written by Lexor on Thu Jan 28 14:49:50 UTC 2010

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?


Written by Raveendran V on Wed Feb 10 15:45:56 UTC 2010

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.


Written by Thanks on Fri Feb 19 22:38:25 UTC 2010

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


Written by omar on Thu Feb 25 09:56:28 UTC 2010

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


Written by omar on Mon Mar 01 07:57:30 UTC 2010

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


Written by dripjax on Mon Mar 08 19:01:04 UTC 2010

Thanks for the plugin this is so sweet. Nevermind my newbie question, just added it to the 2dc_jgrid.rb and boom.


Written by dripjax on Mon Mar 08 23:29:26 UTC 2010

Hello,
Great plugin! However I could not find out how can I apply filters.
For that to work I need to pass my filters as parameters to the actual actions in my controller.
My first idea was to jqGrid('setGridParam',{url:'new_url_with_params'})
but that does not work.


Written by AL on Wed Mar 10 18:16:24 UTC 2010

Thanks for this cool plugin, it works nice. I am have been using this for about a week. Now I have a question and appreciate very much any help.
I want to have a 3 level nested grid with subgrids.
So far I have 2 level working but not the third. I have this simple code based on GrandParents, Parents and Children.
Sorry for the spanish.
here is the code for the view, as I said I before I got the grandParent(abuelos) and Parent(Papas) working but no the children(hijos)

<%= jqgrid("Listing mytrees", "mytrees_jq", "/mytrees",
[
{ :field => "id", :label => "Id" },
{ :field => "name", :label => "Name" }
],
{:edit => true, :inline_edit => true, :autowidth => true, :delete => true,
:edit_url => "/mytrees/post_data", :height => 300,
:subgrid => { :url => "/mytrees/papas",:add => true, :edit => true, :autowidth => true,
:edit_url => "mytrees/papas_post_data" ,
:columns => [
{ :field => "id", :label => "ID", :resizable => true, :editable => false, :hidden => false },
{ :field => "name", :label => "Name", :hidden => false, :editable => true },
],
:subgridgrid => { :url => "mytrees/hijos", :edit => true,
:columns => [
{ :field => "id", :label => "ID", :resizable => true, :editable => false, :hidden => false },
{ :field => "name", :label => "Name", :hidden => false, :editable => true },
],
}
}
}
) %>

Mytrees is the controller for GranParents
Thanks a lot for your help


Written by machetico on Tue Mar 16 05:25:21 UTC 2010

Very nice work! So easy and looks and works great. I hope you plan to update to Rails 3 if changes are necessary.


Written by Fanboy on Wed Mar 17 15:36:35 UTC 2010