Ajoutez des datagrids très facilement à vos applications Ruby on Rails



Ecrit par Anthony Heukmes le 13 avril 2009 14:53

154 commentaires



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 ...
Bookmark and Share

Ajouter un commentaire



154 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

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.


Ecrit par AL le 10 mars 2010 18:16

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


Ecrit par machetico le 16 mars 2010 05:25

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


Ecrit par Fanboy le 17 mars 2010 15:36

Great work on this! I'm trying to get zebra striping going. I know :altRows doesn't work due to some other issue with themes, but does anyone have any other way to do it??

Many thanks


Ecrit par Greg le 25 mars 2010 16:53

Hi,

Thanks for your fantastic work. It will save me an incredible amount of time.
I would just like to mention a workaround for anyone having trouble with "$.jgrid.formatter is undefined" errors. I am developing a Spree extension, and was having this problem because the rails i18n locale was "en-US". Jqgrid doesn't have that locale available in its i18n folder. My fix was to add the bottom line in 2dc_jqgrid.rb around line 11:

def jqgrid_javascripts
locale = I18n.locale rescue :en
locale = :en if locale.to_s.start_with?("en")


Cheers,
Nathan B

You can contact me on my blog post here: http://nathanf77.wordpress.com/2010/04/30/jqgrid-on-spree/


Ecrit par nathan.f77 le 30 avril 2010 05:35

hi,
very nice work, but i don't get it work :-(
i have all done how you described it in the tutorial, but i get always this error:
"Showing users/index.html.erb where line #2 raised:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.present?

Extracted source (around line #2):

1: <h1>1) Simple DataGrid</h1>
2: <%= jqgrid("Football Players", "players", "/users",
"

perhaps anyone can help me.

Thanks


Ecrit par mogliron le 30 avril 2010 09:05

ok, forget my last post ;)

the problem was the ".present?" methode
i have deleted it everywhere and now all works

thank you for your great plugin!!!


Ecrit par mogliron le 30 avril 2010 09:39

I am wondering how can I use this on two models that are "joined" using the has_one/belongs_to relation?


Ecrit par nl0pvm le 01 mai 2010 11:33

Hello,

me again, soory ;)

perhaps anyone could help me
i want to display an image in the grid if a value in the database is true

iam new to ruby on rails, perhaps anyone has an idea

thanks


Ecrit par mogliron le 03 mai 2010 13:35

ok, forgett my last post again ;)

i have solved the problem ;)

anybody who is interested:

in 2dc_jqgrid.rb about line 375
insert:
if value == true
value = "<img src='/images/yourimage.png'>"
end


Ecrit par mogliron le 04 mai 2010 07:38

hi, i'm wonder how can i pass to json, the name of a parent_id, suppose this
model 1
has_many :models2
model 2
belong_to :model1

Model1.find(:all)
i don't want the field model2_id , i want model2.nombre


Ecrit par capitan le 12 mai 2010 04:09

Is there an easy way to pass a list of row that will be "pre"-selected for a multiselect grid?


Ecrit par johnr le 20 mai 2010 02:11

Can i create a jqgrid based on 2 models with has_many/belongs_to relation, i can just use the foreign-key but not a attribute from the other table.

would be awesome if that works, otherwise you have to adjust the views, what i dont think is the good way

One Question more, is it possible to export to excel, pdf or cvs the data based on filtered jqgrid table? or export all data?

thanks in advance


Ecrit par hack2learn le 15 juillet 2010 11:35

Thx a lot. Made some minor modifications to combine enable inline_editing and master_details:
http://www.2shared.com/file/NRmIC7j3/2dc_jqgrid.html


Ecrit par Great Code le 27 juillet 2010 08:12

I need to implement a normal editing functionality, in place of the inline editing like that of add and delete.
How to do that in this pluigin?

Any help would be appreciable?

-- Doel


Ecrit par Doel le 04 août 2010 06:57

capitan & hack2learn

I found a way to use relationships, it took some time, but reading the code really clarify this.
When you pass the attributes to the "to_jqgrid_json" method you have to use single quotes to call the desire relationship.

For example, if i have a table user with a has_many :ticket relationship, and i want to know all the tickets with their respective owners i can do:

tickets.to_jqgrid_json([:id, :customer, :'ticket_user.login'] ......

That's all.


Ecrit par pbruna le 06 août 2010 19:26

I need to reload the child grid on deletion of any row of the master grid.
The data is getting deleted with the association and :dependent => true relation in the model and data from the database but I am not been able to relaod the child grid without manual refresh of the page.

Thanks in advance !!

-- Doel


Ecrit par Doel le 12 août 2010 07:03

thank for you excellent work !!

one question: how can I force a grid to reload (calling controller) from javascript ?


Ecrit par jlg le 19 août 2010 12:00

I follow all the steps and get this error: undefined local variable or method `jqgrid_stylesheets' on index view. During the instalation of 2dc_jqgrid.git and squirrel.git nothing happens neither a sucessfull instalation messagem nor a erro message.


Ecrit par Alex le 19 août 2010 23:32

Nice work!

Some suggestions:

- add custom actions (e.g. edit and delete button on every column with edit and delete link) this for example if one want to use the edit form of rails e.g. /users/1/edit and not the inline edit.
- equal for "new user"
- it is possible to add some code lines to the plugin to add this functionalities?
- here an example: http://www.trirand.com/blog/jqgrid/jqgrid.html on "Row Editing" -> "Custom Editing"

Cheers


Ecrit par phlegx le 26 août 2010 11:00

Awesome grid. Everything looks great except for the horizontal scroll bar. How do I get rid of it. I tried setting :autowidth => true and :width => 500 but no matter how big I make it, I still get the scroll bar.

Anyone seen this?

Thanks


Ecrit par Geolev le 28 août 2010 23:58

I figured out my problem. I had some conflicting CSS in an existing CSS file I used on my site. Once I got rid of them, it all looks great.


Ecrit par Geolev le 30 août 2010 02:23

Hi Anthony,
Do you plan to migrate this plugin to rails 3 soon?
Thanks


Ecrit par Omar le 02 septembre 2010 20:49

Bonjour Anthony,

Merci pour la qualité du travail réalisé.
Est-il prévu une implémentation de cellEdit ?
A défaut, est-il possible d'avoir une idée de son niveau de faisabilité ou bien est-ce hors de portée ?
Sait-on si quelqu'un a pu avancer sur cette question ?
Merci.


Ecrit par mc le 17 septembre 2010 12:33

Hi Anthony, Great stuff you build! Someone was already asking if you ran it already with Rails3 ? Did someone else do it already? What were your findings?
I am going to deploy it with Rails3 and will keep you posted.

Thanks Joop


Ecrit par DutchTraveller le 04 octobre 2010 23:23

Hi Anthony, Thanks for the work to seamlessly integrate this into a rails app. I know the example shows using an .html.erb view, but how hard is it to display in a .json.erb view? I'd like to have two versions of an index view, one with the data grid and one with thumbnails, etc.
My first attempt gave me this error:
ZeroDivisionError in ProductsController#index

divided by 0

So obviously something isn't passing properly.

Thanks,
Greg


Ecrit par gspederson le 20 octobre 2010 15:58

when i tried this plugin i got
undefined local variable or method `jqgrid_stylesheets' for #<ActionView::Base:0x4349808> error.. can you help me in resolving this?


Ecrit par ssri le 19 novembre 2010 06:29

I have done some work to allow this to work in rails 3. I'm also going to also update to the latest version of the jqgrid.

If you would like a copy of the work I've done please let me know else I'm thinking of creating a rails3 fork for people who are interested on github.

darmou


Ecrit par darmou le 23 novembre 2010 22:58

In the tutorial you give examples of how to get the ID of the selected row. How do i get aa value from a different column than the ID? For example, I have an "Name" column. I want to get the value out of the "Name" column rather than the ID. How would i go about doing that?


Ecrit par nkmkek le 28 novembre 2010 20:12

I would really like a rails 3 implementation. if anyone have a link to a project, please don't hesitate to contact me
max@synthmax.dk


Ecrit par Synthmax le 02 décembre 2010 08:25

Hi Darmou,
I would like a copy of your work.
omar.garciapalencia@gmail.com
thanks


Ecrit par omar le 12 décembre 2010 21:23

Very interested in the latest jqgrid and rails 3 as well...


Ecrit par Stevie le 22 décembre 2010 00:52

Wish support for rails 3 and jQuery 1.4.4, jqGrid 3.8.2


Ecrit par Hiro le 07 janvier 2011 14:59

Love the plugin. I have a datetime field in my grid. How can I get a date/time picker? I tried the datepicker but I need to also select the time.


Ecrit par petet le 27 janvier 2011 21:05

Is this compatible with Rails 3.0, I am getting some error


Ecrit par ashish le 02 février 2011 17:54

anyone had luck performing searches without enter key....meaning based on keypress. I believe this would be using searchOnEnter false but haven't had any luck.

Let me know your experiences with this.

Regards.


Ecrit par dmss le 08 février 2011 21:44

Hi, I see that earlier somebody posted the same comment, but I didn't see a response on the board. When I try to run my app, I get this error:

undefined local variable or method `jqgrid_stylesheets'

The same error appears for the javascripts, I followed all of the steps I'm not sure why it isn't being recognized.

Thank you! jsrush91@gmail.com


Ecrit par justin le 19 février 2011 01:26

Hi I am also getting the following error
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.present?

Extracted source (around line #2):

1: <h1>1) Simple DataGrid</h1>
2: <%= jqgrid("Football Players", "players", "/users",

I tried removing the present? from my controller still did not work; can you help me
thanks
hari


Ecrit par hari le 20 février 2011 05:47

Hi, can you add totals/subtotals to your grids?


Ecrit par nicdemor le 18 mars 2011 19:25

Hi.

I just discovered 2dc_jqgrid and I think its great. I do have a few questions - specifically 'how do I intercept the clicking on a checkbox added to a table by setting 'multi_selection' to true ?'

If anyone is interesting in making some $$$ - I'm looking a mentor who can answer some questions and speed my 'learning curve'. If you're interested my email is dekhaus@mac.com

Thanks
Dave


Ecrit par dekhaus le 22 mars 2011 18:16

I found wrong total number when a mod b = 0
I change this line 386 in lib/2dc_grid.rb
from:
json = %Q({"page":"#{current_page}","total":#{total/per_page.to_i+1},"records":"#{total}")
to:
json = %Q({"page":"#{current_page}","total":#{(total/per_page.to_f).ceil},"records":"#{total}")


Ecrit par pukpui le 26 avril 2011 05:06

Hi Anthony,
I intent to use git... $ ./script/plugin install git://.....
it did not work, PLUGIN NOT FOUND...

I used in the console C:\ Windows\system32\cmd.exe

C:\ path.......>.ruby script\plugin install git:// or...... http://

it works...
but

It copy only the dir carpets or foulders ....

RAILS .... /vendor/plugin/2dc_qgrid/ .....
but at the end the carpet 2dc_... is empty.....

Can you help me.... I spend much time....


Ecrit par Sent le 29 avril 2011 09:17

I'm out of laeuge here. Too much brain power on display!


Ecrit par I'm out of laeuge here. Too much brain power on display! le 10 mai 2011 10:47

That's 2 clever by half and 2x2 clever 4 me. Tankhs!


Ecrit par That's 2 clever by half and 2x2 clever 4 me. Tankhs! le 10 mai 2011 20:00

gIeXEZ <a href="http://dgwxfddbcwux.com/">dgwxfddbcwux</a>


Ecrit par gIeXEZ <a href="http://dgwxfddbcwux.com/">dgwxfddbcwux</a> le 11 mai 2011 04:23

NI6kMj , [url=http://udhzpjufwhua.com/]udhzpjufwhua[/url], [link=http://vlmyjutkbhsj.com/]vlmyjutkbhsj[/link], http://gxgsfloalzpq.com/


Ecrit par NI6kMj , [url=http://udhzpjufwhua.com/]udhzpjufwhua[/url], [link=http://vlmyjutkbhsj.com/]vlmyjutkbhsj[/link], http://gxgsfloalzpq.com/ le 11 mai 2011 12:55

Z2wjvc <a href="http://binxzhlwnbxf.com/">binxzhlwnbxf</a>


Ecrit par Z2wjvc <a href="http://binxzhlwnbxf.com/">binxzhlwnbxf</a> le 12 mai 2011 14:59

Hi,
the example that you posted in the github is not working,i am having the same requirements as the examples shown in this site.i need them with rails 3.0.7.can u please help me i this issue.....

thanks in advance............

regards
chaitanya


Ecrit par chaitu le 18 mai 2011 10:20

A0RbjB , [url=http://eqqdzgnesxiz.com/]eqqdzgnesxiz[/url], [link=http://ccsrmbcpvzdh.com/]ccsrmbcpvzdh[/link], http://echolobikspl.com/


Ecrit par A0RbjB , [url=http://eqqdzgnesxiz.com/]eqqdzgnesxiz[/url], [link=http://ccsrmbcpvzdh.com/]ccsrmbcpvzdh[/link], http://echolobikspl.com/ le 28 mai 2011 17:52

XxJ6Hs , [url=http://hijyddyxozij.com/]hijyddyxozij[/url], [link=http://ppnoberfihqr.com/]ppnoberfihqr[/link], http://vppmiicumrsl.com/


Ecrit par XxJ6Hs , [url=http://hijyddyxozij.com/]hijyddyxozij[/url], [link=http://ppnoberfihqr.com/]ppnoberfihqr[/link], http://vppmiicumrsl.com/ le 29 mai 2011 09:33

Hi,
Thank you very much for introducing such a nice plug-in to work with JQuery and Rails.
I have included this plug-in in my rails application that works fine.
I have a doubt when using Data manipulation with inline editing.
The record gets saved when clicking ENTER in the modified row. Moving across rows without pressing 'ENTER' will discards the modified data and the previous values will be restored.
I would like to know whether it is possible to SAVE the data when changing the focus of a cell.
Also, I would like to know, can we use a single ‘SAVE’ button, to save the entire data in the grid without pressing ENTER on each row. For this, we need to get the values in all the cells of all the rows at the server side (currently, getting the values of all the cells in a single row at the server side). Is it possible? If possible, can you please suggest the steps to do?


Ecrit par Thank you very much for introducing such a nice plug-in to work with JQuery and Rails. le 12 août 2011 05:01

Hi,
Thank you very much for introducing such a nice plug-in to work with JQuery and Rails.
I have included this plug-in in my rails application that works fine.
I have a doubt when using Data manipulation with inline editing.
The record gets saved when clicking ENTER in the modified row. Moving across rows without pressing 'ENTER' will discards the modified data and the previous values will be restored.
I would like to know whether it is possible to SAVE the data when changing the focus of a cell.
Also, I would like to know, can we use a single ‘SAVE’ button, to save the entire data in the grid without pressing ENTER on each row. For this, we need to get the values in all the cells of all the rows at the server side (currently, getting the values of all the cells in a single row at the server side). Is it possible? If possible, can you please suggest the steps to do?


Ecrit par Sumesh Babu R , sumeshbabu.r@teamta.in le 12 août 2011 05:03

Followed instuctions explicity. Problem is that what gets returned in the index.erb page is raw unprocessed javascript. Any ideas what I can do?
ed.pabst@yahoo.com

Here is what I'm seeing
Listing crops
<script type="text/javascript"> var lastsel; jQuery(document).ready(function(){ var mygrid = jQuery("#crop_grid").jqGrid({ url:'/crops?q=1', editurl:'', datatype: "json", colNames:['ID','Crop name','Crop type'], colModel:[{name:'id', index:'id',width:35,resizable:false},{name:'cropname', index:'cropname'},{name:'croptype', index:'croptype'}], pager: '#crop_grid_pager', rowNum:10, rowList:[10,25,50,100], imgpath: '/images/jqgrid', sortname: '', viewrecords: true, height: 150, sortorder: '', gridview: false, scrollrows: true, autowidth: false, rownumbers: false, multiselect: false, subGrid:false, caption: "crops" }) .navGrid('#crop_grid_pager', {edit:false,add:false,del:false,search:false,refresh:true}, {afterSubmit:function(r,data){return true;(r,data,'edit');}}, {afterSubmit:function(r,data){return true;(r,data,'add');}}, {afterSubmit:function(r,data){return true;(r,data,'delete');}} ) .navButtonAdd("#crop_grid_pager",{caption:"",title:"Toggle Search Toolbar", buttonicon :'ui-icon-search', onClickButton:function(){ mygrid[0].toggleToolbar() } }) mygrid.filterToolbar();mygrid[0].toggleToolbar() }); </script> <table id="crop_grid" class="scroll" cellpadding="0" cellspacing="0"></table> <div id="crop_grid_pager" class="scroll" style="text-align:center;"></div>


Ecrit par edpabst le 21 août 2011 19:48

Hi edpabst ,
you have to use raw tag to avoid this problem .

Example :<%= raw(jqgrid_javascripts ) %>


Ecrit par prasad le 26 août 2011 08:41

i have the same issue as edpabst. I'm running ruby 1.9.2p290 on Rails 3.0.9. I tried using <%= raw(jqgrid_javascripts ) %> but no change. I'm just getting started on RoR and i know no jQuery i would appreciate any help.


Ecrit par abi le 02 septembre 2011 10:56

Now i've got the previous error solved with prasad's solution but there is no grid is displayed on the page. If there is someone who had it working on rails 3 you may give me a hint here or with
abiasfaw@gmail.com


Ecrit par abi le 02 septembre 2011 11:45

Hi Abi ,
May be it is query wrong , so please use simple like User.all with index.html only .And use https://github.com/springbok/jqgrid-rails3 this pluign . My mail Id prasadmca003@gmail.com

Thank You,
PRASAD.


Ecrit par prasad le 07 septembre 2011 11:23

Hi every one, I need to show data with link to tag or shall I use application helpers here. can any one help please.

Thanks in Advance.


Ecrit par prasad le 07 septembre 2011 12:09

i am using rails 3.0.10..
i could not display any grid in my index page, so anyone please slove my problem...
my index page look like this ....

1) Simple DataGrid


2) Simple DataGrid with selection link/button + search disabled
Get ID of selected row

3) Simple DataGrid with direct selection + autowidth


4) Simple DataGrid with multiple selections + row numbers
Get IDs of selected rows

5) Simple DataGrid with master details ..........


Ecrit par Mani le 13 septembre 2011 12:51

hi to everyone ...

is that possible to use this plugin in rails 3 application ....

i'm using rails 3.0.10 ....

but when i use rails 2.3.5, i can able to display grid, but data's are not displayed ...
i'm getting this follwong error ....

NoMethodError (undefined method `total_entries' for #<Array:0x8c9e1b0>):

plz help me out from this problem ...
very urgent ..
thanks in advance..
Mani


Ecrit par mani le 14 septembre 2011 11:28

Hi Mani ,
Sorry for late reply . Install will paginate 3.0 version . or instead of total entries place size. Example : @users.total_entries => @users.size

Thanks & Regards ,
PRASAD


Ecrit par PRASAD le 17 septembre 2011 17:23

@prasad
Hi prasad thanks for reply ...
my problem solved with your solution ....

I have an another problem, now i am able to display grid with data's from database ....
But i want to display grid with single row with empty textboxes....
Is that possible ???

Thanks in advance
Mani


Ecrit par Mani le 20 septembre 2011 05:06

I am trying to add customButtons, I can't get the format right.
From the code I'm assuming it should be
of the form customButtons=>'[{:caption => etc., ...}]
Looking at the code its looking for the option to be an array containing hashes, yet early on in 2dc_jqgrid.rb all the options are stringified so the option will always be a string, I've inserted some debugging and it does find a string when its looking for an array.
What am I missing?


Ecrit par Laurie le 27 novembre 2011 21:49

Great script,

Is there a way to add a link as a data field?

Thanks!

Jer


Ecrit par JER le 11 janvier 2012 15:29

I have used a similar grid before on ASP.NET and was looking forward to using this one on RoR for a project I'm developing, however I was not able to install the pluggin at all because the script file does not exist anymore. Anyone have the same problem?


Ecrit par josethernandezc le 19 janvier 2012 14:33