douchaqi3369 2013-12-26 18:41
浏览 523
已采纳

JQuery DataTables默认排序无效

My datatable default sorting is not working for some reason that I haven't been able to figure out. The data is displayed correctly though. Pagination is not working either. The first column contains images, but I'm setting it for default to not execute any sort.

Any help is really appreciated.

Here's part of the code I'm using:

var oTable = $('#datatables').dataTable( {
        "aaSorting": [[2, 'asc']],
        "bProcessing": true,
        "bServerSide": true,
        "sPaginationType": "full_numbers",
        "sAjaxSource": "process.php",
        "aoColumns": [
            {
                "mData": null,
                "aTargets": [0],
                "bSerchable": false,
                "bSortable": false,
                "sDefaultContent": '<div class="expand /">',
                "sWidth": "30px"
            },
            { 
                "mDataProp": "email",
                "aTargets": [1],
                "bSearchable": true,
                "bSortable": true
            },
            { 
                "mDataProp": "lastName",
                "aTargets": [2],
                "bSearchable": true,
                "bSortable": true
            },
            { 
                "mDataProp": "firstName",
                "aTargets": [3],
                "bSearchable": true,
                "bSortable": true
            },
            { 
                "mDataProp": "dateRegistered",
                "aTargets": [4],
                "sClass": "center",
                "bSearchable": true,
                "bSortable": true
            }
        ]
    } );

I just added the "aTargets", works the same with our without them.

Here's the file that returns the json array:

<?php

        try {
            $conn = require_once 'dbConnect.php';

            $sql = "SELECT email, lastName, firstName, dateRegistered, state FROM Users";

            $result = $conn->prepare($sql) or die ($sql);

            if(!$result->execute()) return false;

            if($result->rowCount() > 0) {
                $json = array();
                while($row = $result->fetch()){
                    $json[] = array(
                        'email' => $row['email'],
                        'lastName' => $row['lastName'],
                        'firstName' => $row['firstName'],
                        'dateRegistered' => $row['dateRegistered'],
                        'state' => $row['state']
                    );
                }

                $response = array(
                    "iTotalRecords" => strval(count($json)),
                    "iTotalDisplayRecords" => strval(count($json)),
                    "aaData" => $json
                );

                echo json_encode($response);

            }
        } catch(PDOException $e) {
            echo 'Error: ' . $e->getMessage();
        }

?>

Thanks.

  • 写回答

1条回答 默认 最新

  • dqs86517 2013-12-26 21:16
    关注

    After wandering around for a while I was finally able to solve it.

    • Delete or comment the line "bServerSide": true,
    • Instead of using "aoColumns" use "aoColumnDefs"

    And it should work just fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器