###前提・実現したいこと
JAVAEEにてデータベースからSELECTしてきたデータをWebページ上に一覧で表示できたのですが、
表示したセルの上下で同じ値の入っているセルを結合し一つにまとめたいです。
ロジック的には Aセル内の値と のAセル直下のセル内の値が同値のときに
セルを結合し1つにまとめるといった感じです。
###該当のソースコード
xhtmlファイル
xhtml
1<h:body> 2 <h:form prependId="false"> 3 <table class="List" id="ListTable" border="1" > 4 <tr> 5 <th class="Fix" rowspan="2">A</th> 6 <th class="Fix" rowspan="2">B</th> 7 <th class="Fix" rowspan="2">C</th> 8 <th class="Fix" rowspan="2">D</th> 9 <th class="Fix" rowspan="2">E</th> 10 <th class="Flex" rowspan="2">F</th> 11 <th class="Flex" colspan="2">G</th> 12 <th class="Flex" rowspan="2">H</th> 13 <th class="Fix" rowspan="2">I</th> 14 <th class="Fix" rowspan="2">K</th> 15 </tr> 16 <tr> 17 <th class="Flex">From</th> 18 <th class="Flex">To</th> 19 </tr> 20 <ui:repeat var="row" value="#{mainListBean.goallist}"> 21 <tr> 22 <td> 23 <h:outputLabel value="#{row.str003}"/> 24 </td> 25 <td> 26 <h:outputLabel value="#{row.str004}"/> 27 </td> 28 <td> 29 <h:outputLabel value="#{row.str005}"/> 30 </td> 31 <td> 32 <h:outputLabel value="#{row.str006}"/> 33 </td> 34 <td> 35 <h:outputLabel value="#{row.str007}"/> 36 </td> 37 <td> 38 <h:outputLabel value="#{row.str008}"/> 39 </td> 40 <td> 41 <h:outputLabel value="#{row.str009}"/> 42 </td> 43 <td> 44 <h:outputLabel value="#{row.str010}"/> 45 </td> 46 <td> 47 <h:outputLabel value="#{row.str011}"/> 48 </td> 49 <td> 50 <h:outputLabel value="#{row.str012}"/> 51 </td> 52 <td> 53 <h:outputLabel value="#{row.str013}"/> 54 </td> 55 </tr> 56 </ui:repeat> 57 </table> 58 <br/> 59 <br/> 60 <a href="LoginPage.xhtml">ログアウト</a> 61 </h:form> 62 </h:body>
javascriptファイル
javascript
1$(document).ready(function(){ 2 $('#ListTable').each(function () { 3 var pre_element = null; 4 var col_num = 0; 5 $(this).find('tr').each( 6 function () { 7 var now_th = $(this).find('td').eq( col_num ); 8 if (pre_element === null) { 9 pre_element = now_th; 10 } else if (now_th.text() === pre_element.text()) { 11 now_th.remove(); 12 if (pre_element.attr('rowspan') === null) 13 pre_element.attr('rowspan', 1); 14 pre_element.attr('rowspan', parseInt(pre_element.attr('rowspan'),10) + 1); 15 } else { 16 pre_element = now_th; 17 } 18 }); 19 }); 20}); 21
上記javascriptファイルのを使用したのですが、どうしても思うようにセルが結合されません。
結合されるセルもありますが、結合されたセルのある列が左に1セル分ずれてしまします。
よろしく願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。