Front/JS & jQuery

[datatables] columns.data.render

오선지♬ 2022. 5. 8. 11:04
728x90
반응형

EX)

,columns : [
	•••
    
    {data : "REG_DT",
        render : function(data){
            const year = data.substring(0,4);
            const month = data.substring(5,7);
            const day = data.substring(8,10);
            const regdate = year+'.'+month+'.'+day;
            return regdate
        }},
        
     •••
 ]

컬럼명이 "REG_DT"으로 들어오는 데이터 형태가 "yyyy-mm-dd"이었는데,

원하는 출력값은 "yyyy.mm.dd" 이서 데이터를 다시 처리해주어야 했다.

위의 예와 같이 datatables의 option중에서 columns 에서 데이터를 작성해주고,

render속성을 이용하여 데이터를 다시 렌더링 해줄 수 있다.

return값으로 화면에 출력된다.

원래  columnDefs 옵션을 사용해서 데이터 렌더링을 했었는데 위와 같은 방법도 있어서 사용해 보았다.

render: function(data, type, row, meta) {

}

data뿐만아니라 type, row, meta에 관해서도 작업해줄 수 있다.

 

 

https://datatables.net/examples/basic_init/data_rendering.html

 

 

DataTables example - Data rendering

Data rendering Data within DataTables can be easily rendered to add graphics or colour to your tables, as demonstrated in the example on this page. These examples make use of columns.render to customise the cells in three ways: A flag is added to the Offic

datatables.net

 

728x90
반응형