【问题标题】:DataTables, Ajax Pipelining数据表、Ajax 流水线
【发布时间】:2011-10-03 23:14:27
【问题描述】:

我正在使用带有 pipelining 的 DataTables。我工作得很好,除非我尝试输入一个额外的列来保存“编辑”链接。请参阅this 表。

这是 server_processing.php 的 sn-p 显示列:

   /* Array of database columns which should be read and sent back to DataTables.
    * Use a space where you want to insert a 
    * non-database field (for example a counter or static image)
    */
    $aColumns = array( 'user','email', ); 

这里是客户端:

    $(document).ready( function (){
       $('#example').dataTable({
          "bProcessing": true,
          "bServerSide": true,
          "sAjaxSource": "scripts/server_processing.php",
          "fnServerData": fnDataTablesPipeline,
          aoColumns: [null, null, {"bSortable": false}]
    }).makeEditable({
       sUpdateURL: "UpdateData.php",
       sAddURL: "AddData.php",
       sAddHttpMethod: "POST",
       sDeleteURL: "DeleteData.php",
       sDeleteHttpMethod: "POST",
       aoColumns: [ { } , { } , null ]
    });
  });

那么,为什么这不起作用?

【问题讨论】:

  • 我对 DataTables 的体验不包括使用流水线,但是在添加“虚拟列”时 - 例如,编辑列、复选框、计算行,通常您需要为其添加占位符你的aoColumns 数组。所以我会将aoColumns: [null, null, {"bSortable": false}]aoColumns: [null, null, {"bSortable": false}] 更改为aoColumns: [null, null, null, {"bSortable": false}]
  • 另外,如果您有任何问题,编写 dataTables 的人(我认为是 Alan Jardine?)非常善于提供帮助。他非常乐于助人,显然没有人比创作者本人更了解插件!

标签: php javascript jquery ajax datatables


【解决方案1】:

我自己也做了同样的事情。我喜欢使用aoColumnDefs 配置我的所有列,因为您可以一次性为列添加多个配置选项。

// Disable sorting on the 3rd column
'aoColumnDefs': [{'aTargets': [2], 'bSortable': false}]

请注意,aTargets 是您要应用这些设置的列索引数组。因此,如果您要添加更多链接列(例如删除链接),您可以关闭这些列的排序,而无需每次都重写列定义。

// Disable sorting on the 3rd and 4th column
'aoColumnDefs': [{'aTargets': [2,3], 'bSortable': false}]

而且,正如我所说,您可以为同一数组中的列添加更多配置选项:

// Disable sorting on the 3rd and 4th column and sort 1st column by string
'aoColumnDefs': [
    {'aTargets': [2,3], 'bSortable': false}
    {'aTargets': [0], 'sType': 'string'}
]

【讨论】:

    猜你喜欢
    • 2022-07-14
    • 2014-01-24
    • 2012-05-26
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2021-09-29
    相关资源
    最近更新 更多