简体   繁体   English

Datatable的columnDefs中的目标

[英]targets in columnDefs of Datatable

The documentation tells us the way we can use 'targets' in columnDefs. 文档告诉我们在columnDefs中可以使用“目标”的方式。 But is there any way we can use it dynamically? 但是,有什么方法可以动态使用它? For example, I have a global array (containing column numbers) which I update every time certain function is carried out on datatable. 例如,我有一个全局数组(包含列号),每次对数据表执行某些功能时都会更新该数组。 I want to render those columns in the global array in a particular fashion. 我想以一种特殊的方式在全局数组中呈现这些列。 I need to know if there is any way in which I could do this. 我需要知道是否有任何方法可以做到这一点。

"columnDefs":[
  {
    "targets": hide_them,//name of the global array
    "render": //some function
  }
]

As per documentation Target of columnDefs in Datatable must use for below approach 根据文档 ,Datatable中的columnDefs Target必须用于以下方法

0 or a positive integer column index counting from the left 0或从左开始计数的正整数列索引

$('#example').dataTable( {
  "columnDefs": [ {
      "targets": 0,
      "searchable": false
    } ]
} );

A negative integer such as column index counting from the right 负整数,例如从右边开始计数的列索引

$('#example').dataTable( {
      "columnDefs": [ {
          "targets": -0,
          "searchable": false
        } ]
    } );

_all - A string - class name will be matched for all column as default work _all-字符串-类名将与所有列匹配,作为默认工作

$('#example').dataTable( {
          "columnDefs": [ {
              "targets": '_all',
              "searchable": false
            } ]
        } );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM