[javascript] datatable <tr>,<td>에 속성과 스타일 추가하기

겸구미·2023년 10월 6일

javascript/jQuery

목록 보기
4/5

문제상황

datatable 라이브러리를 사용하던 도중, 데이터를 불러와 넣을 때 조건에 따라 <tr>에 css를 적용해야 했다.

문제해결

  • datatable <tr>에 속성 추가하기
    • css, attr 등 다른 설정도 가능

createdRow: function(row, data, dataIndex, full) { $(row).css('text-decoration', 'line-through'));

function callback(data) {
	table1 = #('#table').DataTable({
   		"data":data,
        "columns":[
        	{"data":"col1"}
            ,{"data":"col2"}
            ,{"data":"col3"}
        ],
        "coulmnDefs":[
        	{targets:0, width:"100px"}
            ,{targets:1, width:"100px"}
            ,{targets:2, width:"100px"}
		],
        createdRow: function(row, data, dataIndex, full) {
        	$(row).css('text-decoration', 'line-through'));
        }
    },
});

<tr><td>에 접근하기

$(row).children('td:nth-child(1)').css('text-decoration', 'line-through');
profile
머신learning

0개의 댓글