jQuery datatables columnDefs目标名称而不是索引

时间:2021-01-14 14:25:36

In this code:

在这段代码中:

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

targets has been given a column index. But in my case, columns can be in varying orders. So my question is, can "targets" be given the name of the column parameter and if so, how?

目标已被赋予列索引。但就我而言,列可以按不同的顺序排列。所以我的问题是,“目标”可以给出列参数的名称,如果是,如何?

1 个解决方案

#1


15  

From the documentation (emphasis mine):

从文档(强调我的):

This targets property tells DataTables which column(s) the definition should be applied to. It can be:

此目标属性告诉DataTables应该应用定义的列。有可能:

  • 0 or a positive integer - column index counting from the left
  • 0或正整数 - 从左数起的列索引
  • A negative integer - column index counting from the right
  • 一个负整数 - 从右边开始计数的列索引
  • A string - class name will be matched on the TH for the column
  • 字符串的类名将匹配在列的TH上
  • The string "_all" - all columns (i.e. assign a default)
  • 字符串“_all” - 所有列(即分配默认值)

#1


15  

From the documentation (emphasis mine):

从文档(强调我的):

This targets property tells DataTables which column(s) the definition should be applied to. It can be:

此目标属性告诉DataTables应该应用定义的列。有可能:

  • 0 or a positive integer - column index counting from the left
  • 0或正整数 - 从左数起的列索引
  • A negative integer - column index counting from the right
  • 一个负整数 - 从右边开始计数的列索引
  • A string - class name will be matched on the TH for the column
  • 字符串的类名将匹配在列的TH上
  • The string "_all" - all columns (i.e. assign a default)
  • 字符串“_all” - 所有列(即分配默认值)