2017-05-08 1 views
0

도와주세요. 내가 잘못 가고 있는지 확실하지 않다. 첫 번째 열에 의해 테이블을 정렬하고 싶다. 몇 가지 변형을 시도했지만 정렬이 제대로 작동하지 않습니다.Datatable : 정렬 작동하지 않습니다.

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

같은 시도 할 수 있습니다 당신을 위해이 일을 했습니까? – kblau

답변

1

이것은 내가 수행 한 것이며 정렬은 첫 번째 열에서 작동합니다.

@{ 
    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> 
0

당신이

dataTable = $("#deptDtTable").dataTable({ 
     "bFilter" : false 
     ....... 
     "aaSorting": [[ 0, "desc" ]] // Sort by first column descending 
     ...... 
}); 
관련 문제