simple-datatable 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -3
- data/lib/datatable/application.rb +13 -1
- data/simple-datatable.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ae017add1485f1d27addbb38987d6248ebdf6b3f34300ca4eec66b67cce04fe
|
4
|
+
data.tar.gz: b15f26ee3c907bb0c9018749d4783864dbb7fafbef006ce652819292cc509644
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d841027417996a1b12e8bcff666b66a77694b20c532a92797b52017409f34594914aed6883a069cea143ca697ff0e4ebe43b9c7cc3ea17c7769edb702681c223
|
7
|
+
data.tar.gz: 9522b5a65d164bfbebcc1dcdb4b2167238bea34743fbfd782ed03348771a62a4a8107a502ddd0121071eade82ed39aec2fa3d45fb4d1ff3ca82320be9890718d
|
data/README.md
CHANGED
@@ -50,20 +50,83 @@ in your file ```application.js```
|
|
50
50
|
add gem
|
51
51
|
|
52
52
|
```
|
53
|
-
gem '
|
53
|
+
gem 'simple-datatable'
|
54
54
|
|
55
55
|
```
|
56
56
|
|
57
|
-
|
57
|
+
It also depends on:
|
58
|
+
|
58
59
|
|
59
60
|
```
|
60
|
-
|
61
|
+
gem 'will_paginate', '~> 3.1.0'
|
62
|
+
|
61
63
|
```
|
62
64
|
|
63
65
|
Automatically we are created a folder with the structure of the tables ```app/datatables```.
|
64
66
|
|
65
67
|
## Usage
|
66
68
|
|
69
|
+
|
70
|
+
Generate model with structure datatables, open your terminal and write:
|
71
|
+
|
72
|
+
```
|
73
|
+
$ datatable g model_name
|
74
|
+
```
|
75
|
+
|
76
|
+
|
77
|
+
Example Controller:
|
78
|
+
|
79
|
+
```
|
80
|
+
# Query with data
|
81
|
+
@clients = Client.all
|
82
|
+
|
83
|
+
# Format table
|
84
|
+
data = %w[clients.id clients.name clients.lastname clients.address]
|
85
|
+
respond_to do |format|
|
86
|
+
format.html
|
87
|
+
format.json { render json: ClientsDatatable.new(view_context, @clients, data) }
|
88
|
+
end
|
89
|
+
|
90
|
+
```
|
91
|
+
|
92
|
+
View:
|
93
|
+
|
94
|
+
```
|
95
|
+
<table id="datatable" class="table datatable_table table-hover" role="grid" data-source="<%= clients_path(format: :json) %>" cellspacing="0">
|
96
|
+
<thead>
|
97
|
+
<tr>
|
98
|
+
<th>ID</th>
|
99
|
+
<th>Name</th>
|
100
|
+
<th>Last Name</th>
|
101
|
+
<th>Address</th>
|
102
|
+
</tr>
|
103
|
+
</thead>
|
104
|
+
|
105
|
+
<tbody>
|
106
|
+
<!-- leave blank -->
|
107
|
+
</tbody>
|
108
|
+
</table>
|
109
|
+
```
|
110
|
+
|
111
|
+
Folder datatable:
|
112
|
+
|
113
|
+
```
|
114
|
+
class ClientsDatatable < ApplicationDatatable
|
115
|
+
private
|
116
|
+
def data
|
117
|
+
dimension.map do |dimension|
|
118
|
+
[
|
119
|
+
# Add your attributes
|
120
|
+
dimension.id,
|
121
|
+
dimension.name,
|
122
|
+
dimension.lastname,
|
123
|
+
dimension.address,
|
124
|
+
]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
67
130
|
### Quickstart
|
68
131
|
|
69
132
|
|
@@ -4,6 +4,8 @@ module Datatable
|
|
4
4
|
include Rails.application.routes.url_helpers
|
5
5
|
include ActionView::Helpers::TagHelper
|
6
6
|
include ActionView::Helpers::NumberHelper
|
7
|
+
include ActionView::Helpers::SanitizeHelper
|
8
|
+
|
7
9
|
delegate :params, :h, :link_to, :image_tag, :current_user, to: :@view
|
8
10
|
|
9
11
|
def initialize(view, model, items, order_items=nil, pre_filter=false, filter='')
|
@@ -22,7 +24,7 @@ module Datatable
|
|
22
24
|
sEcho: params[:draw].to_i,
|
23
25
|
iTotalRecords: @model.count,
|
24
26
|
iTotalDisplayRecords: dimension.total_entries,
|
25
|
-
aaData: data
|
27
|
+
aaData: sanitize_data(data)
|
26
28
|
}
|
27
29
|
end
|
28
30
|
|
@@ -95,5 +97,15 @@ module Datatable
|
|
95
97
|
asset = asset.get_asset
|
96
98
|
end
|
97
99
|
|
100
|
+
def sanitize_data data
|
101
|
+
# sanitize data, when the persistent (or stored) Cross-site scripting vulnerability
|
102
|
+
data.each do |row|
|
103
|
+
row.each_with_index do |attribute, index|
|
104
|
+
row[index] = sanitize(row[index]) if row[index].is_a? String
|
105
|
+
end
|
106
|
+
end
|
107
|
+
data
|
108
|
+
end
|
109
|
+
|
98
110
|
end
|
99
111
|
end
|
data/simple-datatable.gemspec
CHANGED