유동적인 테이블 Td 셀 병합 rowspan 처리 Javascript 함수
지정 항목의 tr > td 값에 값이 동일 한 경우 rowspan 처리해주는 Javascript 함수입니다.
주석 처리된 라인의 경우 contains 를 사용하여 포함된 조건이어서 일부 상황에서 정렬에 의해 해당 Row 사이에 다른 Row가 존재하는 경우 문제가 생길수 있는 상태인데
원작자의 글 댓글에 일치하는 조건으로 코드 개선해주신분이 계셔서 취합했습니다.
$(document).ready(function(e){
genRowspan("td 클래스명");
});
function genRowspan(className){
$("." + className).each(function() {
//var rows = $("." + className + ":contains('" + $(this).text() + "')");
var sText = $(this).text();
var rows = $("." + className).filter(function() {
return $(this).text() == sText;
});
if (rows.length > 1) {
rows.eq(0).attr("rowspan", rows.length);
rows.not(":eq(0)").remove();
}
});
}
https://zero-gravity.tistory.com/311
[jQuery] 유동적인 테이블 셀병합 - rowspan
위와 같이 소속에 같은 데이터가 있을 경우 하나의 셀로 병합해주는 코드다. $(document).ready(function(e){ genRowspan("td 클래스명"); }); function genRowspan(className){ $("." + className).each(funct..
zero-gravity.tistory.com
https://api.jquery.com/contains-selector/
:contains() Selector | jQuery API Documentation
Description: Select all elements that contain the specified text. The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value selectors, text inside the parenthe
api.jquery.com