質問編集履歴

2

前後の処理を追加しました

2020/01/17 01:57

投稿

yuujiMotoki
yuujiMotoki

スコア90

test CHANGED
File without changes
test CHANGED
@@ -91,3 +91,167 @@
91
91
  チェックボックスを押すと、on/off という風にテキストが変わるようにするには、
92
92
 
93
93
  どういうマクロを組み込めばいいでしょうか?
94
+
95
+
96
+
97
+
98
+
99
+ #追加内容
100
+
101
+ テーブルの読込、書出のソースを追加しました。
102
+
103
+ 対象となっているテーブルは、CSVデータから生成しており、
104
+
105
+ 更新後には、CSVデータとして排出されます。
106
+
107
+
108
+
109
+ テーブルへのチェックボックスは、単なる入力支援として入れたい状況です。
110
+
111
+ あと実際には、チェックボックス化したいカラムは、動的にデータを読み込んだ後に、
112
+
113
+ 動的に追加という形になります
114
+
115
+ (出力時には、その内容を消すような処理が必要です)
116
+
117
+
118
+
119
+ ```javascript
120
+
121
+
122
+
123
+ var data;
124
+
125
+ var rownum = 0;
126
+
127
+ $.ajax({
128
+
129
+ type: "GET",
130
+
131
+ url: '{{csvname}}',
132
+
133
+ dataType: "text",
134
+
135
+ success: function (response) {
136
+
137
+ data = $.csv.toArrays(response);
138
+
139
+ generateHtmlTable(data);
140
+
141
+ $("#target").tablesorter();
142
+
143
+ }
144
+
145
+ });
146
+
147
+ function generateHtmlTable(data) {
148
+
149
+ var html = '<table id="target" align="center" >';
150
+
151
+ if (typeof (data[0]) === 'undefined') {
152
+
153
+ return null;
154
+
155
+ } else {
156
+
157
+ $.each(data, function (index, row) {
158
+
159
+ //bind header
160
+
161
+ if (index == 0) {
162
+
163
+ html += '<thead>';
164
+
165
+ html += '<tr>';
166
+
167
+ $.each(row, function (index, colData) {
168
+
169
+ html += '<th label=num>';
170
+
171
+ html += colData;
172
+
173
+ html += '</th>';
174
+
175
+ });
176
+
177
+ html += '</tr>';
178
+
179
+ html += '</thead>';
180
+
181
+ html += '<tbody>';
182
+
183
+ } else {
184
+
185
+ html += '<tr>';
186
+
187
+ $.each(row, function (index, colData) {
188
+
189
+ html += '<td>';
190
+
191
+ html += colData;
192
+
193
+ html += '</td>';
194
+
195
+ });
196
+
197
+ html += '</tr>';
198
+
199
+ }
200
+
201
+ });
202
+
203
+ html += '</tbody>';
204
+
205
+ html += '</table>';
206
+
207
+ $('#csv-display').append(html);
208
+
209
+ set_number();
210
+
211
+ count_num();
212
+
213
+ }
214
+
215
+ }
216
+
217
+
218
+
219
+ function saveing() {
220
+
221
+ var data = $('#target').tableToJSON();
222
+
223
+ $.ajax({
224
+
225
+ type: "POST",
226
+
227
+ url: "/csvout" + document.getElementById('fname').value,
228
+
229
+ contentType: 'application/json; charset=UTF-8',
230
+
231
+ data: JSON.stringify(data),
232
+
233
+ dataType: 'json',
234
+
235
+ success: function (data) {
236
+
237
+ window.location.reload(true);
238
+
239
+ console.log(data);
240
+
241
+ },
242
+
243
+ error: function (error) {
244
+
245
+ console.log(data);
246
+
247
+ alert("もう一度クリックしてください。");
248
+
249
+ },
250
+
251
+ });
252
+
253
+ }
254
+
255
+
256
+
257
+ ```

1

new

2020/01/17 01:57

投稿

yuujiMotoki
yuujiMotoki

スコア90

test CHANGED
File without changes
test CHANGED
@@ -84,10 +84,10 @@
84
84
 
85
85
 
86
86
 
87
+ #質問内容
88
+
89
+
90
+
87
91
  チェックボックスを押すと、on/off という風にテキストが変わるようにするには、
88
92
 
89
93
  どういうマクロを組み込めばいいでしょうか?
90
-
91
-
92
-
93
- #質問内容