/*
*
* 같은 값이 있는 열을 병합함
*
* 사용법 : $(`#테이블 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).re();
// 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(); // .re();
} else {
that = this;
}
// set the that if not already set
that = (that == null) ? this : that;
});
});
});
}
//셀병합 호출 방법
//첫번째 열을 병합한다.
$(`#테이블 ID`).rowspan(0);
'JSP·script·jquery' 카테고리의 다른 글
jqgrid paging (0) | 2015.05.18 |
---|---|
jquery table 데이터 컨트롤 로우 클릭시 컬럼데이터 가져오기 (0) | 2015.05.17 |
jsp 서블릿 압축 방법 (0) | 2014.09.19 |
jquery 로딩시 select box 변경값 체크 (0) | 2014.04.15 |
jstl c태그 과 스크립틀릿 사이의 데이터 공유 (0) | 2014.04.02 |