2016-11-25 26 views
0

我使用javascript DataTable,並將我被通過API鏈接獲取該數據填充表:的Javascript的dataTable - 添加鏈接表

jQuery.get(api_url_here", function(dataSet){ 

    jQuery('#myTable').DataTable({ 
     data: dataSet, 
     columns: [ 
      { "data": "id", "title": "theId" }, 
      { "data": "name", "title": "theName" } 
     ] 
    }); 


}); 

<table id="myTable" class="display"></table> 

這一切工作的要求,但我需要的一個列有創建,這樣當用戶點擊該ID就會去用id指定的URL的鏈接...

例如:<a href="someurl+{id}">theId</a>

我怎樣才能做到這一點與dataTable的?

回答

1
"ajax": "./pasien/look/", 
aoColumns: [ 
    { "mData": null } 
], 
columnDefs: [{ 
    "targets": 0, 
    "data": null, 
    "mRender": function (data, type, row) { 
    return '<a href="#">'+ row.mr +'</a>'; 
} 
}] 

試試這個,我用數據表中的數據使用ajax。

0

嘗試這樣的:

  { 
       "data": "id", 
       "title": "theId", 
       "aTargets": [0], 
       "sType": "numeric" 
      }, 
      { 
       "className":  '', 
       "orderable":  false, 
       "data":    null, 
       "defaultContent": '<a href="your link"</a>' 
      }]; 
0

jQuery有一個事件,多數民衆贊成開除創建單元格時,你就可以寫普通的JavaScript來設置它的內容與ID:

jQuery.get("api_url_here", function(dataSet){ 
    jQuery('#myTable').DataTable({ 
     data: dataSet, 
     columns: [ 
      { "data": "id", "title": "theId", 
       "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) { 
        $(nTd).html("<a class='display' href='" + oData.id + "'>" + oData.id + "</a>"); 
       } 
      }, 
      { "data": "name", "title": "theName" } 
     ] 
    }); 
}); 

我希望它能幫助你。

我從https://www.datatables.net/forums/discussion/25111/hyperlink-in-td得到了答案。