Front/JS & jQuery

[jQuery][datatables] tbody colspan

오선지♬ 2022. 6. 23. 18:33
728x90
반응형

var table = $('#example').DataTable({
    ajax: 'https://gyrocode.github.io/files/jquery-datatables/arrays.json',
    createdRow: function(row, data, dataIndex){
        // If name is "Ashton Cox"
        if(data[0] === 'Ashton Cox'){
            // Add COLSPAN attribute
            $('td:eq(1)', row).attr('colspan', 3);

            // Hide required number of columns
            // next to the cell with COLSPAN attribute
            $('td:eq(2)', row).css('display', 'none');
            $('td:eq(3)', row).css('display', 'none');

            // Update cell data
            this.api().cell($('td:eq(1)', row)).data('N/A');
        }
    }
});

 

➡️ 0번째 열의 데이터가 'Ashton Cox' 일 때,

   인덱스 1인 행에  'colspan = 3 '속성 을 부여한다. 

   인덱스 2,3 인 행은 보여주지 않는다. ( 'display = none ' 속성을 부여 )

   인덱스 1인 행에 'N/A' 라는 데이터를 넣는다.

 

참고: https://www.gyrocode.com/articles/jquery-datatables-colspan-in-table-body-tbody/

 

jQuery DataTables: COLSPAN in table body TBODY | Gyrocode.com

Provides a solution to use COLSPAN attribute for a cell in table body with jQuery DataTables.

www.gyrocode.com

 

728x90
반응형

'Front > JS & jQuery' 카테고리의 다른 글

[jQuery] filter()  (0) 2022.06.27
[js] 화살표 함수 ( Arrow Function )  (0) 2022.06.26
[js] NaN → 0으로 처리하기  (0) 2022.06.21
[js] 배열의 합  (0) 2022.06.19
[js] 숫자 배열 정렬하기 - sort()  (0) 2022.06.17