본문 바로가기
javascript

[dataTables.js] row 추가 row.add()

by 바나냥 2020. 4. 20.

dataTables.js에서 수정시

build: function build() {
    this.datatable = this.$table.DataTable({
        aoColumns: [null, null, null, null, null, { //col개수
            "bSortable": false
         }],     
         lengthMenu: false,
         searching: false,
         "info": false,
         "paging": false
    });
    
},
rowAdd: function rowAdd() {

     data = this.datatable.row.add(['', '', '', '', '', actions]); //col개수
     
     this.datatable.order([0, 'desc']).draw(); //asc:오름차순 desc:내림차순

 

 

html에서 javascript 추가시

$('#addToTable').on( 'click', function () {
  var actions, data, $row;
  actions = ['<a href="#" class="btn btn-sm btn-icon btn-pure btn-default on-default remove-row"><i class="icon md-delete" aria-hidden="true"></i></a>'].join(' ');

  data = myTable.row.add( [
    '', '', '', '', '', '', ''
  ] ).draw();
  $row = myTable.row(data[0]).nodes().to$();
  $row.addClass('adding').find('td:last').addClass('actions');
  $('#table_paging').rowEdit($row);
  myTable.order([0, 'desc']).draw(); // always show fields

  //this.$addButton.tooltip('hide');
} );

 

 

 

col개수에 맞게 null, '' 을 추가한다.

 

댓글