2015-06-03 25 views

回答

1

我找到了答案。我們需要在jtable的字段部分添加此代碼

customDelete: { 
    title: '', 
    width: '0.3%', 
    display: function(data) { 
    var $but = $('<button title="delete" class="jtable-command-button jtable-delete-command-button" >delete</button>'); 
       $but.click(function(){ 
        var $dfd = $.Deferred(); 
        if(data.record.configType == 'global') 
        { 
         alert('Global Type Configuration are not allowed for deletion.') 
         return false; 
        } 
        if (confirm('Are you sure you want to delete this?')) { 
         $.ajax({ 
          url: '/admin/configuration/delete', 
          type: 'POST', 
          dataType: 'json', 
          data: data.record, 
          success: function (data) { 
           $dfd.resolve(data); 
           $('#Container').jtable('load') ; 

          }, 
          error: function() { 
           $dfd.reject(); 
          } 
         }); 
       } 
      }); 
      return $but; 
     } 
    }, 
} 
0

您可以編寫自定義函數來刪除,而不僅僅是URL。當doin添加你想發送數據的字段時,通過ajax發送。請參閱下面的代碼以及文檔http://www.jtable.org/demo/FunctionsAsActions

$('#Container').jtable({ 
     //...other code 
     actions: { 
      deleteAction: function (postData) { 
        console.log("deleting from custom function..."); 
        //Attach your values to postData... 
        //make sure you collect it in controller/code 
        postData.customData = $('#myinput').val(); 
        return $.Deferred(function ($dfd) { 
         $.ajax({ 
          url: '/Demo/DeleteStudent', 
          type: 'POST', 
          dataType: 'json', 
          data: postData, 
          success: function (data) { 
           $dfd.resolve(data); 
          }, 
          error: function() { 
           $dfd.reject(); 
          } 
         }); 
        }); 
       }, 
      //...other actions 
     }, 
    }); 

    //Load student list from server 
    $('#Container').jtable('load'); 
}); 
相關問題