2016-02-12 33 views
0

我有以下的DataTable添加具有引導按鈕的div jQuery的數據表列

 <script> 
      $(document).ready(function() { 
       $("#productTable").DataTable({ 
        "info": false, 
        "processing": true, // for show progress bar 
        "serverSide": true, // for process server side 
        "filter": false, // this is for disable filter (search box) 
        "orderMulti": false, // for disable multiple column at once 
        "ajax": { 
         "url": "/Home/LoadProductData", 
         "type": "POST", 
         "datatype": "json" 
        }, 
        "columns": [ 
          { "data": "Product_ID", "name": "Product_ID", "autoWidth": true }, 
          { "data": "Product_Title", "name": "Product_Title", "autoWidth": true }        
           ] 
       }); 
      }); 
     </script> 

現在我想補充以下div具有引導按鈕

<div class="btn-group btn-group-sm" id="CreateButton"> 
    <button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("Product_Edit","Home", new { })';return false;">Edit</button> 
</div> 

這是可以直接插入?如果沒有,如何配置?

+0

你想在所有行的列中添加此按鈕? – tmg

+0

@tmg,yp正好 – kez

回答

0

使用render

'columns': [ 
      { 
       'render': function (data, type, full, meta) { 
        return '<button type="button" class="btn btn-warning">Edit</button>'; 
       } 
      }, 
... 

我注意到你正在使用MVC剃刀語法生成URL,這讓我覺得你是包括在視圖中的數據表初始化代碼。爲了避開這個,你需要生成這樣的按鈕:

<a class=\'btn\' href=\'' + $("#rooturl").val() + '/Home/Product_Edit/' + full[0] + '\'>Edit</a>'; 

$("#rooturl")是包含應用程序的URL隱藏字段。 我假定Product_Edit操作方法接受參數Product_ID。這樣你就可以使用數據錶行數據將id附加到url。