数据表列宽重置问题

时间:2018-01-16 12:31:06

标签: jquery html css datatables

我想从js。

给出datatable(Fixed Header)的最大宽度

我使用以下js来更新数据表ssetting:

<th>

但在申请&#34; sScrollY&#34;列宽未正确设置。 因此,我只想重置每个<tr><section class="panel"> <header class="panel-heading"> Scheduled Outages </header> <div class="panel-body"> <div class="adv-table"> <table class="display table table-bordered table-striped" id="example1"> <thead> <tr> <th>Id</th> <th>Planned Start Date</th> <th>Planned End Date</th> <th>D...</th> <th class="hidden-phone">Ho...</th> <th class="hidden-phone">Syst...</th> <th class="hidden-phone">Area</th> <th class="hidden-phone">Loc Name</th> <th class="hidden-phone">Loc Unit</th> </tr> </thead> <tbody> <tr class="gradeX"> <td>65</td> <td>01/17/2018 00:00:00</td> <td>01/22/2018 00:00:00</td> <td class="center hidden-phone">5</td> <td class="center hidden-phone">0</td> <td class="center hidden-phone">Mainline</td> <td class="center hidden-phone">Kennedy Ave(WO01)</td> <td class="center hidden-phone">Kennedy Ave</td> <td class="center hidden-phone">Meter Loopline</td> </tr> </tbody> <tfoot> <tr> <th>Id</th> <th>Planned Start Date</th> <th>Planned End Date</th> <th>D...</th> <th class="hidden-phone">Ho...</th> <th class="hidden-phone">Syst...</th> <th class="hidden-phone">Area</th> <th class="hidden-phone">Loc Name</th> <th class="hidden-phone">Loc Unit</th> </tr> </tfoot> </table> </div> </div> </section> 的列宽。

我已经尝试了一切可能的方法。

HTML代码: -

transactions_plot <- function(Gross,FS_Rlse_Split,Failed,name1,name2,name3){

       plot_ly(grand_aggregate_FSID_transactionData, x = ~as.factor(Year), 
            y = ~Gross, 
            name = name1, type = 'scatter', mode = 'lines+markers') %>%
      add_trace(y = ~FS_Rlse_Split, 
                name = name2, 
                mode = 'lines+markers') %>%
      add_trace(y = ~Failed, 
                name = name3, 
                mode = 'lines+markers') %>%
      layout(xaxis = list(tickangle =45,
                          title = ""),
             yaxis = list(title = "")
      )
}


if(input$transaction_View_Type_choose == "TXAmt"){

   transactions_plot('Gross_Value',
                     'FS_Rlse_Split_Usd',
                     'Failed_TX_Sum',
                     'Gross Value',
                     'FS Release USD',
                     'Failed Transactions Value')      
}else{

   transactions_plot('Gross_TXN',
                     'FS_Rlse_Split_TXN',
                     'Failed_TXN',
                     'Gross Transactions',
                     'FS Release Transactions',
                     'Failed Transactions')
}

图片: -

enter image description here

2 个答案:

答案 0 :(得分:1)

看看columns.adjust()

var oTable = $('#example').DataTable({
  sScrollY: 200px,
  initComplete: function() {
    this.api().columns.adjust().draw()
  }
})

答案 1 :(得分:0)

我不熟悉DataTables,但也许你没有写过“滚动”信息。正确?

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