유동적인 테이블 Td 셀 병합 rowspan 처리 Javascript 함수

Open API/그 외 |2021. 7. 22. 10:22
반응형

지정 항목의 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

 

댓글()

jQuery 여러개의 Class가 적용된 객체 선택하기

Open API/Jquery|2018. 11. 29. 10:50
반응형

How can I select an element with multiple classes in jQuery?

- without space.

여러개의 클래스가 지정된 객체를 선택하고자 할 때.. 어떻게 해야할까

- 띄어쓰기 없이 해야함.

<span class="a b c">multiple classes</span>


$(".a.b.c").trigger("click")




댓글()

jquery ajax 동기처리가 안되는 경우.. async 옵션이 적용 안될 때.

Open API/Jquery|2017. 9. 20. 18:59
반응형

jQuery ajax 옵션중에는 async 옵션이 있습니다.

이것은 기본적으로 ajax가 비동기 처리를 하지만 필요에 따라 동기 요청을 하기 위한 옵션이지만

최근 경험상 적용이 되지 않는 것이 확인되어 api 사이트를 확인해보니 

아래와 같은 내용이 확인이 됩니다.


크로스 도메인일 경우 데이터 타입이 jsonp라면 지원되지 않는다. 

위의 조건 외에도 1.8 버전 이후부터 지원되지 않음이라고 명시되어있고 

콜백 함수를 이용하도록 명시가 되어있으니 

1.8버전 혹은 최신 버전을 사용하는 경우 문제가 될 것같습니다.


그런데...되는 경우도 있고..안되는 경우도 있고...모호하네요.


확실하게 그냥 콜백 함수를 사용해야겠습니다.


 

  async (default: true)
  Type: Boolean
By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp"requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done().


http://api.jquery.com/jQuery.ajax/

댓글()