【问题标题】:Uneven Sorting in DataTable数据表中的不均匀排序
【发布时间】:2026-01-20 21:15:02
【问题描述】:

我的 HTML 如下所示。

<table id="address_datatable" class="table table-bordered table-striped">
   <thead>
       <tr>
         <th></th>
         <th>Company Name</th>
         <th>Contact Name</th>
         <th>Email Address</th>
         <th>Phone Number</th>
         <th>Action</th>
      </tr>
   </thead>
 <tbody>

我的 jQuery 代码如下所示

$(document).ready(function() {
            $('#address_datatable').DataTable({
                "columnDefs": [ {
                "targets": [ 0, 2 ],
                "orderable": false
                } ]
            });
   });

2 在 "targets" 中工作,但 0 不工作。

我也试过下面的例子。它不工作

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

为什么会这样?

【问题讨论】:

    标签: twitter-bootstrap datatables-1.10


    【解决方案1】:

    试试这个方法

    在 HTML 中

    <table id="address_datatable" class="table table-bordered table-striped">
       <thead>
           <tr>
             <th></th>
             <th>Company Name</th>
             <th>Contact Name</th>
             <th>Email Address</th>
             <th>Phone Number</th>
             <th class="nosort">Action</th>
          </tr>
       </thead>
     <tbody>
    

    在 JS 中

     $('#address_datatable').dataTable( {
          "columnDefs": [ {
              "targets": 'nosort',
              "orderable": false
            } ]
        } );
    

    【讨论】:

      【解决方案2】:

      请为您的问题添加更多详细信息.. 你是用ajax数据源还是简单的静态表数据?

      如果 ajax 执行以下操作。

      ajax:{
      type:'post', // whatever method
      url:"your url"
      },
        "columns": [
      //Specify your columns here
       ],
      columnDefs:[
      //Column definitions here
      ]
      } );
      

      【讨论】:

      • 感谢@Navaneth Raman Bhaskar。但是 2 在这里工作 "targets": [ 0, 2 ],。谢谢。
      • 我正在使用简单静态表。
      • @abuabu 看到这个文档datatables.net/manual/data/orthogonal-data
      • 冲突解决 检查冲突: 1. 列中定义的属性将始终优先于 columnDefs 中定义的该属性的任何值。 2. columnDefs 数组中较高的属性将优先于下面的。