table rowspan 테이블 rowspan 합치는 jquery

2015. 4. 9. 07:09IT/Jquery Plugin/Tip


table rowspan 테이블 rowspan 합치는 jquery

 -----> 이렇게 바꿔 주는 Jquery입니다.




<?

$colspan = 5;
if ($is_checkbox) $colspan++;
?>
    <table cellspacing="0" cellpadding="0" class="board_list">
<? if


($is_checkbox) { ?><col width="20" /><? } ?>
<col width="100" />
<col width="90" />
<col width="170" />
<col />
<!-- <col width="100" />
<col width="100" /> -->
    <tr>
        <? if ($is_checkbox) { ?><th><input onclick="if (this.checked) all_checked(true); else all_checked(false);" type="checkbox"></th><?}?>
<th>직 &nbsp; 위</th>
        <th>성 &nbsp; 명</th>
        <th>업  &nbsp; 체  &nbsp; 명</th>
        <th>업  &nbsp; 체 &nbsp; 주 &nbsp; 소</th>
        <!-- <th>전화번호</th>
        <th>팩스번호</th> -->
    </tr>
    <? for ($i=0; $i<count($list); $i++) { ?>
    <tr> 
        <? if ($is_checkbox) { ?><td class="checkbox"><input type=checkbox name=chk_wr_id[] value="<?=$list[$i][wr_id]?>"></td><? } ?>
<td class="">
<?php echo $list[$i]['ca_name'] ?></a>
</td>
        <td class="">
            <?if($member[mb_level]>8){?><a href="<?=$list[$i][href]?>"><?php echo $list[$i]['subject'] ?></a><?}else{?><?php echo $list[$i]['subject'] ?><?}?>
        </td>
        <td class="" style="text-align:left; text-indent:10px;"><?=$list[$i]['wr_content']?></td>
        <td class="" style="text-align:left; text-indent:10px;"><?=$list[$i]['wr_1']?></td>
        <!-- <td class=""><?=$list[$i]['wr_2']?></td>
        <td class=""><?=$list[$i]['wr_3']?></td> -->
    </tr>
    <? } // end for ?>

    <? if (count($list) == 0) { echo "<tr><td colspan='$colspan' style='line-height:120px; text-align:center;'>게시물이 없습니다.</td></tr>"; } ?>

    </table>
 <? if ($is_checkbox) { ?>
<script>$('.board_list').rowspan(1);</script>
<?}else{?>
<script>$('.board_list').rowspan(0);</script>
<?}?>


<script>

/* 
* 같은 값이 있는 열을 병합함
* 사용법 : $('#테이블 ID').rowspan(0);
*/    
$.fn.rowspan = function(colIdx, isStats) {       
return this.each(function(){      
var that;     
$('tr', this).each(function(row) {
$('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
 
if ($(this).html() == $(that).html()
&& (!isStats 
|| isStats && $(this).prev().html() == $(that).prev().html()
)
) {            
rowspan = $(that).attr("rowspan") || 1;
rowspan = Number(rowspan)+1;

$(that).attr("rowspan",rowspan);
 
// do your action for the colspan cell here            
$(this).hide();
 
//$(this).remove(); 
// do your action for the old cell here
 
} else {            
that = this;         
}          
 
// set the that if not already set
that = (that == null) ? this : that;      
});     
});    
});  
}; 


/* 
* 같은 값이 있는 행을 병합함
* 사용법 : $('#테이블 ID').colspan (0);
*/  
$.fn.colspan = function(rowIdx) {
return this.each(function(){
 
var that;
$('tr', this).filter(":eq("+rowIdx+")").each(function(row) {
$(this).find('th').filter(':visible').each(function(col) {
if ($(this).html() == $(that).html()) {
colspan = $(that).attr("colSpan") || 1;
colspan = Number(colspan)+1;
 
$(that).attr("colSpan",colspan);
$(this).hide(); // .remove();
} else {
that = this;
}
 
// set the that if not already set
that = (that == null) ? this : that;
 
});
});
});
}

</script>



table rowspan 테이블 rowspan 합치는 jquery