2016-07-25 155 views
0

jQuery DataTables reference顯示了一個將rowId選項設置爲來自數據源(服務器端)的列的示例。此設置用於「選擇」擴展名和retaining row selection on Ajax reload如何生成jQuery DataTables rowId客戶端?

是否有任何方法來生成行標識符值1)客戶端,或2)作爲來自數據源的多列的組合?

實例數據來源:

{ 
    "data": [ 
    { 
     "aid": 5421, 
     "bid": 4502, 
     "name": "John Smith" 
    } 
} 

代碼:

$("#datatable").DataTable({ 
    select: true, 
    //rowId: "aid" each row ID is the value of the "aid" column 
    //  e.g., <tr id="5421"> 

    //rowId: 0 each row ID is the value of the 0-indexed column 
    //  e.g., <tr id="5421"> (same as above) 

    rowId: [0, 1] // How? row ID combined value of 2+ columns 
        // e.g. <tr id="5421-4502"> 

    rowId: "random" // How? random generated client-side ID 
        // e.g., <tr id="id34e04"> 
}); 

回答

1

顯然有沒有辦法直接做到這一點。作爲解決方法,您可以使用ajax.dataSrc選件和/或rowId選件:

// Example using dataSrc option to manipulate data: 
$("#example").dataTable({ 
    ajax: { 
     url: "data.json", 
     dataSrc: function (json) { 
      for (var i = 0, ien = json.data.length; i < ien; i++) { 
       json.data[i][0] = '<a href="' + json.data[i][0] + '">View Message</a>'; 
      } 
     } 
    } 
});