2016-09-28 57 views
0

我有一個數據表設置爲從服務器讀取JSON。但是其中一列應該按照其隱藏索引與屏幕上顯示的內容進行排序。Datatables只按int排序,錯誤

這是我要顯示錶:

 $("#ad-table").dataTable({ 
      "lengthMenu": [[100, 50, 25], [100, 50, 25]], 
      "ajax": { 
       "url": "assessmentsduetable?peid="+peId, 
       "dataSrc": "" 
      }, 

      dom: 'Bfrtip', 
      "buttons": ['print', 'pageLength'], 
      "order": [[4, "asc"]], 
      "columns": [ 
      { "data": "Consumer ID" }, 
      { "data": "Last Name" }, 
     { 
      "data": { 
       _: "WindowNameInfo.WindowDue", 
       sort: "WindowNameInfo.WindowDueIndex" 

      } 
     }, 
      { "data": "Window End Date" }, 
      { "data": "Days Left In Window" }, 
      { "data": "Assessment Name" }, 
      { "data": "Date of Last Assessment" }, 
      { "data": "# of Assessments" }, 
      { "data": "Clinician" }, 
      { "data": "Clinic" } 
      ] 
     }); 



    }); 

問題是與WindowNameInfo.WindowDue和WindowNameInfo.WindowDueIndex。出於某種原因,它似乎在WindowDueIndex上進行排序,就好像它是一個字符串,即使它是一個整數。然而,當我這樣做:

"data": { 
        _: "WindowNameInfo.WindowDue", 
        sort: "WindowNameInfo.WindowDueIndex", 
        type: "int" 

       } 

我得到以下錯誤:

DataTables warning: table id=ad-table - Requested unknown parameter '[object Object]' for row 0, column 2. For more information about this error, please see http://datatables.net/tn/4

然後它加載表和排序是正確的!

回答

0

原來的類型選項告訴DataTables在哪裏獲取數據以用於類型檢測。

所以答案是:

...

"data": { 

        _: "WindowNameInfo.WindowDue", 
        sort: "WindowNameInfo.WindowDueIndex", 
        type: "WindowNameInfo.WindowDueIndex", 
       } 

...