2016-07-23 55 views
0

我有serverside分頁datatable與定義下面,它工作正常,但事情是;一個字段包含太長,所以我需要設置一個細節按鈕,而不是它,當其點擊彈出顯示並查看描述的數據。在渲染前編輯jquery dt響應

我試過將success:function(aaData){..}添加到ajax中,但是它會中止數據表的任何建議?我不想編輯壽模型控制器我在瀏覽器中的數據,所以我想在這裏處理這個..

$(document).ready(function() { 
     var table = $('#dtBooks').DataTable({ 
      "processing": true, 
      "serverSide": true, 
      "filter": false, 
      "orderMulti": false, 
      "ajax": { 
       "url": "@Url.Action("GetBooks", "Home")", 
       "type": "POST", 
       "datatype": "json" 

      }, 

      "columns": [ 
       { "data": "Title", "name": "Title", "autoWidth": true }, 
       { "data": "Publisher", "name": "Publisher", "autoWidth": true }, 
       { "data": "Description", "name": "Description", "autoWidth": true }, 
       { "data": "Authors", "name": "Authors", "autoWidth": true }, 
      ] 
    }); 
    }); 

這裏是這個模型的數據表的模型認定中contorller響應列表。

public class Book 
    { 
     public string Title { get; set; } 
     public string Publisher { get; set; } 
     public string Description { get; set; } 
     public string[] Authors { get; set; } 
    } 

回答

1

您可以使用ajax.dataSrc選項來操作從服務器返回的數據。

例如:

$('#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="/message/'+json.data[i][0]+'>View message</a>'; 
     } 
     return json.data; 
    } 
    } 
}); 
+0

voaw的這麼快,exaclty我期待..東西謝謝老兄.. – TyForHelpDude