simple_grid 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -42
- data/lib/simple_grid/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -5,28 +5,27 @@ SimpleGrid is the most easy way to transform your CRUD in a powerful jQuery Data
|
|
5
5
|
## Requisites
|
6
6
|
|
7
7
|
* Rails 3.1 (asset pipeline) - You can run it in minor versions but you need to add the assets manually (not tested yet).
|
8
|
-
* ActiveRecord
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
|
12
11
|
Install the gem:
|
13
12
|
|
14
|
-
|
13
|
+
$ gem install simple_grid
|
15
14
|
|
16
15
|
Add this line to your Rails application Gemfile:
|
17
16
|
|
18
|
-
|
17
|
+
gem 'simple_grid'
|
19
18
|
|
20
19
|
Execute:
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
$ bundle install
|
22
|
+
$ rails generate simple_grid:install
|
24
23
|
|
25
24
|
Include the SimpleGrid helper in your ApplicationHelper:
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
module ApplicationHelper
|
27
|
+
include SimpleGrid::Helpers
|
28
|
+
end
|
30
29
|
|
31
30
|
Load the assets in your application.
|
32
31
|
|
@@ -34,44 +33,48 @@ Load the assets in your application.
|
|
34
33
|
|
35
34
|
Is very easy to use the SimpleGrid gem, suppose that we have the tables Books and Authors. Each book has an author and an author has many books.
|
36
35
|
|
37
|
-
To use the gem in our book index view we need to call the method simple_grid. Like
|
36
|
+
To use the gem in our book index view we need to call the method simple_grid. Like below:
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
<%= simple_grid(@books) %>
|
39
|
+
# The first parameter is our records based on ActiveRecord.
|
40
|
+
# In this example it will display a grid with all table columns and the actions show, edit and destroy.
|
42
41
|
|
43
42
|
The second parameter can be an options hash, see the examples below:
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
44
|
+
In this example it will not display the columns present in :exclude_columns array
|
45
|
+
|
46
|
+
<%= simple_grid(@books, :exclude_columns => ["id","description","created_at","updated_at"]) %>
|
47
|
+
|
48
|
+
In this example it will not display the columns "id" and "description" but it will display an extra column with the author name based in our relationship.
|
49
|
+
|
50
|
+
<%= simple_grid(@books, :exclude_columns => ["id","description"],
|
51
|
+
:extra_columns => {
|
52
|
+
:author_name => { :label => "Author", :relationship => "author.name" }
|
53
|
+
}) %>
|
54
|
+
# The :label key is the column title and the :relationship key is our models relationship.
|
55
|
+
|
56
|
+
In this example it will add a new column with label "New column" and the content as html.
|
57
|
+
|
58
|
+
<%= simple_grid(@books, :exclude_columns => ["id","description"],
|
59
|
+
:extra_columns => {
|
60
|
+
:author_name => { :label => "Author", :relationship => "author.name" },
|
61
|
+
:other_column => { :label => "New Column", :content => "<strong>Content</strong>" }
|
62
|
+
}) %>
|
63
|
+
|
64
|
+
In this example it will display the actions based in the hash options.
|
65
|
+
|
66
|
+
<%= simple_grid(@books, :exclude_columns => ["id","description"],
|
67
|
+
:extra_columns => {
|
68
|
+
:author_name => { :label => "Author", :relationship => "author.name" }
|
69
|
+
},
|
70
|
+
:actions => {
|
71
|
+
:show => { :label => "View", :html => { :id => "show_info" } },
|
72
|
+
:edit => { :route => "my_route" },
|
73
|
+
:destroy => { :display => false }
|
74
|
+
}) %>
|
75
|
+
# The action show will be displayed with label "View" and the id "show_info" in the html element.
|
76
|
+
# The action edit will use the route "my_route" (it will interprete as "my_route(record)").
|
77
|
+
# The action destroy will not be displayed.
|
75
78
|
|
76
79
|
## TODO
|
77
80
|
|
data/lib/simple_grid/version.rb
CHANGED