2016-08-29 5 views
0
$('#some-table').DataTable({ 
"language": { 
    "url": "{{ asset('/js/plugins/lang.json') }}" 
}, 
"ordering": false, 
"scrollX": true, 
"scrollCollapse": false, 
"searching": false, 
"processing": true, 
"serverSide": true, 
"scrollY": 400, 
"ajax": { 
    "url": "/ajax/url", 
    "type": "POST", 
    "data": function (d) { 
     d.some_parametr = '123'; 
    } 
}, 
"columns": [ 
    {data: 'some_category', name: 'table.some_category'}, 
    {data: 'day.1', name: 'table.day'}, 
    {data: 'day.2', name: 'table.day'}, 
    {data: 'day.3', name: 'table.day'}, 
    {data: 'day.4', name: 'table.day'}, 
    ... 
    {data: 'day.30', name: 'table.day'}, 
    {data: 'day.31', name: 'table.day'}, 
], 
"initComplete": function (settings, json) { 
    var api = this.api(); 
    if (json.extra) { 
     var stat_day; 
     for (var i = 1; i < 32; i++) { 
      stat_day = json.extra.stat.day[i];    
      $(".dataTables_scrollFootInner table tfoot tr").append($('<td>') 
       .html(stat_day) 
      ); 
     }           
    } 
    // Sync TFOOT scrolling with TBODY 
    $('.dataTables_scrollFoot').on('scroll', function() { 
     $('.dataTables_scrollBody').scrollLeft($(this).scrollLeft()); 
    }); 
} 

페이지가로드 열 테두리가 동일하지 크기를 조정할 열의 다른 폭 : 브라우저 창 크기를 변경 한 후 enter image description here - 모든 열이 정렬 : enter image description here의 jQuery DataTables : 페이지가로드 후에는

페이지를로드 할 때 테이블 열이 정렬되도록하려면 어떻게해야합니까?

+0

무엇을 기대 했습니까? 바닥 글에 ''31 개를 삽입하여 테이블 크기를 조정할 때까지 전체 레이아웃을 나눕니다. – davidkonrad

+0

옵션 "autoWidth": false' ..이게 도움이되기를 바랍니다. – mmushtaq

+0

@ davidkonrad 감사합니다. api.draw() –

답변

0

을,이 문제에 대한 올바른 해결책은 초기화 후 테이블을 다시 그리기 사용하는 것입니다 api.draw를();

"initComplete": function (settings, json) { 
var api = this.api(); 
if (json.extra) { 
    var stat_day; 
    for (var i = 1; i < 32; i++) { 
     stat_day = json.extra.stat.day[i];    
     $(".dataTables_scrollFootInner table tfoot tr").append($('<td>') 
      .html(stat_day) 
     ); 
    }           
} 
// Sync TFOOT scrolling with TBODY 
$('.dataTables_scrollFoot').on('scroll', function() { 
    $('.dataTables_scrollBody').scrollLeft($(this).scrollLeft()); 
}); 

api.draw(); 

} 
0

이 시도 : 내 경우

columnDefs: [ 
    { width: 200, targets: 0 } // this will set width of first column 
], 
fixedColumns: true // this will set the column width to fixed 
+0

감사합니다. 그러나이 방법으로 원하는 결과를 얻을 수 없습니다. –