개발을 요구사항중에 row의 값이 같은경우 해당 cell을 merge하라는 요구사항을 접수.
솔직히 아래의 로직은 구글링을 통해 많이 검색되는 함수..
그와는 별개로 $.fn.메소드명을 아래와 같이 정의하고 사용할 수 있다.
$("#id").메소드();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/*
*
* 같은 값이 있는 열을 병합함
*
* 사용법 : $('#테이블 ID').rowspan(0);
*
*/
$.fn.rowspan = function(colIdx, isStats) {
return this.each(function(){
var that;
$('tr', this).each(function(row) {
$('td',this).eq(colIdx).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;
});
});
});
};
|
cs |
이번 포스팅을 통해 JQuery에서 나만이 정의해논 함수를 선언하고 사용하고싶다면
위와같은방법으로 사용하면 좋을것 같다.
'IT > 개발' 카테고리의 다른 글
JAVA CSV파일 엑셀에서 열때 숫자를 문자로 인식 (0) | 2019.09.09 |
---|---|
JSP JSTL fmt 기능 (0) | 2019.09.08 |
java.net.SocketException: There is no process to read data written to a pipe. (0) | 2019.09.07 |
JAVA 파일다운로드 파일명 한글깨짐 (0) | 2019.09.06 |
P tag 반응형 및 자동들여쓰기 (0) | 2019.09.04 |