質問編集履歴

2

2016/06/28 13:51

投稿

yuji38kwmt
yuji38kwmt

スコア437

test CHANGED
File without changes
test CHANGED
@@ -14,6 +14,18 @@
14
14
 
15
15
 
16
16
 
17
+ 結合セルに含まれている列を、表示/非表示切り替えようとしています。
18
+
19
+ デフォルトは非表示です。
20
+
21
+
22
+
23
+ D列は`data-column="3"`を期待していますが、Web開発ツールで確認すると`data-column="2"`でした。
24
+
25
+ これは、B-2列が非表示のため「1列ない」とtablesorterが認識したのだと思います。
26
+
27
+
28
+
17
29
  ```html
18
30
 
19
31
 

1

2016/06/28 13:51

投稿

yuji38kwmt
yuji38kwmt

スコア437

test CHANGED
File without changes
test CHANGED
@@ -16,36 +16,138 @@
16
16
 
17
17
  ```html
18
18
 
19
- <table id="sampleTable">
20
-
21
- <thead>
22
-
23
- <tr><th colspan="2">地域</th><th rowspan="2">人口[千人]</th></tr>
24
-
25
- <tr><th>県</th><th>市</th></tr>
26
-
27
- </thead>
28
-
29
- <tbody>
30
-
31
- <tr><td>Aichi</td><td>Nagoya</td><td>2200</td></tr>
32
-
33
- <tr><td>Gifu</td><td>Takayama</td><td>301</td></tr>
34
-
35
- <tr><td>Toyama</td><td >Toyama</td><td >300</td></tr>
36
-
37
- </tbody>
38
-
39
- </table>
19
+
20
+
21
+ <!DOCTYPE html>
22
+
23
+ <html>
24
+
25
+ <head>
26
+
27
+ <meta charset="UTF-8">
28
+
29
+ <title>Insert title here</title>
30
+
31
+
32
+
33
+ <script src="../web-lib/jquery-2.1.3.min.js"></script>
34
+
35
+ <script src="../web-lib/jquery.tablesorter.combined.min.js"></script>
36
+
37
+
38
+
39
+ <style>
40
+
41
+ table, tr, td, th {
42
+
43
+ border: solid 1px;
44
+
45
+ }
46
+
47
+ </style>
48
+
49
+ </head>
50
+
51
+ <body>
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+ <table id="sampleTable">
60
+
61
+ <thead>
62
+
63
+ <tr>
64
+
65
+ <th rowspan="2">A列</th>
66
+
67
+ <th id="mergedCell" colspan="1" >B列</th>
68
+
69
+ <th rowspan="2">D列</th>
70
+
71
+ </tr>
72
+
73
+
74
+
75
+ <tr>
76
+
77
+ <th >B-1列</th>
78
+
79
+ <th class="hide" style="display:none;">B-2列</th>
80
+
81
+ </tr>
82
+
83
+ </thead>
84
+
85
+ <tbody>
86
+
87
+ <tr><td>a</td><td>b</td><td class="hide" style="display:none;">1</td><td>d</td></tr>
88
+
89
+ <tr><td>d</td><td>a</td><td class="hide" style="display:none;">2</td><td>c</td></tr>
90
+
91
+ </tbody>
92
+
93
+ </table>
94
+
95
+
96
+
97
+ <script>
98
+
99
+ //初期処理
100
+
101
+ $("#sampleTable").tablesorter();
102
+
103
+
104
+
105
+ /**
106
+
107
+ * 3列目を非表示/表示を切り替える
108
+
109
+ * @param hide true:非表示, false:表示
110
+
111
+ */
112
+
113
+ function hideColumn(hide) {
114
+
115
+ if (hide) {
116
+
117
+ $("#sampleTable .hide").css("display", "none");
118
+
119
+ document.getElementById("mergedCell").colSpan=1;
120
+
121
+ } else {
122
+
123
+ $("#sampleTable .hide").css("display", "");
124
+
125
+ document.getElementById("mergedCell").colSpan=2;
126
+
127
+ }
128
+
129
+ //tablesorterの更新
130
+
131
+ $("#sampleTable").trigger("updateAll");
132
+
133
+ }
134
+
135
+ </script>
136
+
137
+
138
+
139
+
140
+
141
+ </body>
142
+
143
+ </html>
144
+
145
+
40
146
 
41
147
  ```
42
148
 
43
149
 
44
150
 
45
- ![ヘッダが結合しているテーブル](e994b5b0f42c4cbad32e15863e724652.png)
46
-
47
-
48
-
49
151
 
50
152
 
51
153
  ###発生している問題