Jquery DataTable不居中

vulvrdjw  于 2023-11-17  发布在  jQuery
关注(0)|答案(1)|浏览(136)

我开始学习如何使用dataTables,我用它来显示我从Excel文件导入的一些JSON数据。我有表显示,但它不是与标题居中。我一直在寻找一个解决方案很长一段时间,但我还没有找到一个。
代码包含在一个片段中,并显示输出的屏幕截图。

/* set up XMLHttpRequest */

var url = "LICENCIAMENTOS.xlsx";
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";

oReq.send();
oReq.onload = function(e) {
  var arraybuffer = oReq.response;

  /* convert data to binary string */
  var data = new Uint8Array(arraybuffer);
  var arr = new Array();
  for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
  var bstr = arr.join("");

  /* Call XLSX */
  var workbook = XLSX.read(bstr, {
    type: "binary"
  });

  /* DO SOMETHING WITH workbook HERE */

  var first_sheet_name = workbook.SheetNames[5];
  //var address_of_cell='A5';

  /* Get worksheet */

  var worksheet = workbook.Sheets[first_sheet_name];
  v = XLSX.utils.sheet_to_json(worksheet);

  //DataTable                           
  $('#data-table').DataTable({
    "aaData": v,
    "aoColumns": [{
        "mData": "Cenas",
        sDefaultContent: ''
      },
      {
        "mDataProp": "PT",
        sDefaultContent: ''
      },
      {
        "mDataProp": "kV",
        sDefaultContent: ''
      },
      {
        "mDataProp": "S/A",
        sDefaultContent: ''
      },
      {
        "mDataProp": "NOME",
        sDefaultContent: ''
      },
      {
        "mDataProp": "SGD",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Comprimento (m)",
        sDefaultContent: ''
      },
      {
        "mDataProp": "EDIS",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Licenciamento Externo",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Data Execucao",
        sDefaultContent: ''
      },
      {
        "mDataProp": "APE",
        sDefaultContent: ''
      },
      {
        "mDataProp": "DREC/DRELVT",
        sDefaultContent: ''
      },
      {
        "mDataProp": "A-P-E-",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Editos - GBCI",
        sDefaultContent: ''
      },
      {
        "mDataProp": "GBCI-Recortes",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Editos - ME",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Estradas",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Refer",
        sDefaultContent: ''
      },
      {
        "mDataProp": "ICN",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Txas-NI",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Taxas-Pag.",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Licenciamento",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Pedido de Vistoria",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Licenca de Exploracao",
        sDefaultContent: ''
      },
      {
        "mDataProp": "DRE  161.10.03.----",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Avisos",
        sDefaultContent: ''
      },
      {
        "mDataProp": "Observacoes",
        sDefaultContent: ''
      },
      {
        "mDataProp": "IF",
        sDefaultContent: ''
      },
      {
        "mDataProp": "SGD",
        sDefaultContent: ''
      },
      {
        "mDataProp": "DTA PGT",
        sDefaultContent: ''
      }
    ]
  });
}

个字符


的数据

vktxenjb

vktxenjb1#

margin: 0 auto;添加到表style

<table id="data-table" style="text-align:center; margin: 0 auto;" >

字符串
它会自动调整水平边距,使您的表格居中

相关问题