什么是使用数组更改Datatables列的正确格式? [英] What is the right format to change Datatables column using array?

查看:94
本文介绍了什么是使用数组更改Datatables列的正确格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在初始化表格后,我试图更改数据表的列号:

I'm trying to change the column numbers of my Datatables after I initial the table:

其中retitle是一个数组(即长度为4的数组),而c是先前定义的retitle的长度(即c = 4).

where retitle is an array (i.e. an array of length 4) and c is the length of retitle (i.e. c=4), which is previously defined.

   var atarget = [];
   var stitle = [];
   for(var i=0; i<c; i++){
     atarget[i] = i;
     stitle[i] = retitle[i];
   }

var oTable = $('#table_id').dataTable({
 "bPaginate": false,
 "bProcessing": true,
 "bLengthChange": true,
 "bFilter": true,
  "bRetrieve": true,
 "bInfo": false,
 "bAutoWidth": false,
 "bServerSide": true,
 "sDom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
 "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
 "sAjaxSource": './aadata.txt',
 "aoColumnDefs": [
    {"sTitle":stitle,"aTargets":aTarget}
  ]

 }); 

但这根本不起作用.

推荐答案

我通过更改HTML中初始化表的方式而不是更改数据表中的设置来解决了这个问题.

I solved the question by changing the way of initialising table in HTML instead of altering the settings in Datatables.

我要做的是:首先,删除现有表以及表包装器!

What I did is: first, remove the existing table, as well as the table wrapper!

 $('#table_id').remove();
 $('#table_id_wrapper').remove();

然后初始化一个新表.并根据您的数据设置页眉/正文的格式:

Then initialise a new table. and set the format of header/body according to your data:

 var content = "<table id='table_id' class='display datatable' style='width:100%;'><thead>";
 content +='<tr>';


 re = re.substring(0,re.length-1);
 // alert(re);
 var retitle = re.split(",");
    alert (retitle + 'x');
   var c = retitle.length;
   var atarget = [];
   var stitle = [];
   for(var i=0; i<c; i++){
     atarget[i] = i;
     stitle[i] = retitle[i];
     content += '<td>' +retitle[i]  + '</td>';

   }

  content +=' </tr></thead>';
  content +='<tbody></tbody>'
  content += "</table>";

最后,将表格添加到网页上.在这里,我将其附加到了我的标签:

Finally, append your table to your webpage. Here I attached it to my tab:

  $('#tab3').append(content);

顺便说一句,谢谢您,@ Volkan Ulukut对您的帮助都一样.

By the way, thank you, @Volkan Ulukut all the same for your help.

这篇关于什么是使用数组更改Datatables列的正确格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆