数据表:排序不起作用 [英] Datatable: sorting not working

查看:83
本文介绍了数据表:排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助.我不确定我要去哪里错 我希望该表按第一列排序.我尝试了几种变体,但是排序无法正常工作

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 '';
                }
            }
        } ]
    });

推荐答案

这就是我所做的,排序工作在第一列上.

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>

这篇关于数据表:排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆