2014-07-02 85 views
4

在jQuery數據表中,如何在綁定服務器數據時動態綁定複選框列?jQuery DataTable - 動態綁定複選框列與服務器數據

我的代碼:

oTable = $("#tblPreProcess").dataTable({ 
      bProcessing: true, 
      bLengthChange: false, 
      bFilter: true, 
      sAjaxSource: '@Url.Action("FetchPreprocessOrders", "Admin")', 
      aoColumns: [ 
       { sTitle: "Order No", bSortable: false ,bSearchable: true}, 
       { sTitle: "Vol.Weight", bSortable: false }, 
       { sTitle: "Content", bSortable: false, },    
       { sTitle: "Bag Number", bSortable: false }        
      ]    

     }); 

在上面給出的代碼,我怎麼「訂單號」列前添加一個複選框列。

+2

綁定該複選框,以什麼樣的數據? – davidkonrad

+0

檢查此:http://stackoverflow.com/a/14131236/1059101 – Jai

回答

2

你可以做到這一點像下面的代碼:

oTable = $("#tblPreProcess").dataTable({ 
      bProcessing: true, 
      bLengthChange: false, 
      bFilter: true, 
      sAjaxSource: '@Url.Action("FetchPreprocessOrders", "Admin")', 
      aoColumns: [ 
       { sTitle: "Select", bSortable: false , 
       mRender: function (data, type, full) 
       { 
        return '<input type="checkbox" class="selector" data-id="'+ data +'">' 
       }, 
       { sTitle: "Order No", bSortable: false ,bSearchable: true}, 
       { sTitle: "Vol.Weight", bSortable: false }, 
       { sTitle: "Content", bSortable: false, },    
       { sTitle: "Bag Number", bSortable: false }        
      ]    

     });