??yy 2017-05-08 20:57 采纳率: 0%
浏览 58

数据表:排序不起作用

Please help. I am not sure where I am going wrong I want the table to be sorted by the first column. I tried several variations, but sort is not working properly

dataTable = $("#deptDtTable").dataTable({
        "bFilter" : false
        "bProcessing" : true,
        "bServerSide" : true,
        "bSort" : true,
        "bStateSave" : false,
        "iDisplayLength" : 25,
        "iDisplayStart" : 0,
        "fnDrawCallback" : function() {
        },      
        "sAjaxSource" : "/url/url/datatable/dept",
        "aaSorting": [[ 1] ],
        "aoColumns" : [ 
            {
            "mData" : 'id'
        }, {
            "mData" : 'client_name' 
        }, {
            "mData" : 'ssn'
        }, {
            "mData" : 'department'
        }, {
            "mData" : 'account_id'
        }, {
            "mData" : 'dateEntered', 
            "render" : function(data) {
                if (data !== null) {
                    var date = new Date(data);
                    return date.toLocaleString();
                } else {
                    return '';
                }
            }
        } ]
    });
  • 写回答

2条回答 默认 最新

  • 七度&光 2017-05-09 03:36
    关注

    This is what I did, and the sorting works on the first column.

    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index62</title>
        <script src="~/Scripts/jquery-1.12.4.min.js"></script>
        <script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
        <link href="~/Content/DataTables/css/jquery.dataTables.min.css" rel="stylesheet" />
        <script type="text/javascript">
            $(document).ready(function () {
                  $('#example').
                    dataTable({
                    "processing": true,
                    "serverSide": true,
                    "info": true,
                    "stateSave": true,
                    "ajax": {
                        "url": "/Home/AjaxGetJsonData",
                        "type": "GET"
                    },
                    "columns": [
                        { "data": "Name", "orderable": true },
                        { "data": "Age", "orderable": false },
                        { "data": "DoB", "orderable": true }
                    ],
                    "order": [[0, "asc"]]
                });
            });
    
        </script>
    </head>
    <body>
        <div style="margin:30px;">
            <table id="example" class="display" cellspacing="0" width="100%">
                <thead>
                    <tr style="text-align:left;">
                        <th>Name</th>
                        <th>Age</th>
                        <th>DoB</th>
                    </tr>
                </thead>
    
                <tfoot>
                    <tr style="text-align:left;">
                        <th>Name</th>
                        <th>Age</th>
                        <th>DoB</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改