Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

blog

[DataTables] row Select 기능 추가(선택한 행의 data 값 가져오기) 본문

Web/front-end

[DataTables] row Select 기능 추가(선택한 행의 data 값 가져오기)

hjkongkong 2022. 3. 5. 22:38

DataTables에서 아주 간단하게 기능을 추가할 수 있다.

https://datatables.net/download/index

Select기능을 추가해서 Download files

이렇게 네개 추가

$('#dataTable').DataTable({
	select: true
});

한 줄 선택 가능

공식에서 다양한 select 기능을 제공한다.

https://datatables.net/extensions/select/examples/initialisation/single.html

 

DataTables example - Single item selection

Single item selection The select.style option provides the ability to control how items are selected in the table. It is a string that can be used with one of the following options: api - Selection can only be performed via the API single - Only a single i

datatables.net


https://datatables.net/reference/api/rows().data()

 

rows().data()

rows().data() Since: DataTables 1.10 Get the data for the selected rows. Description This method is used to get the data used for the cells in the rows matched by the selector from DataTables. The order of the data in the returned array and which rows the

datatables.net

선택한 행의 data 값 가져오기는 API를 이용해서 구현한다.

// select check
$('#dataTable tbody').on( 'click', 'tr', function () {
	this_row = table.rows(this).data();
	alert("모든 데이터: "+table.row( this ).data()+
	" name : "+this_row[0][0]+" office:"+this_row[0][2]);
} );

js에 추가

alert로 데이터 확인