2017-02-09 9 views
1

을 삭제 한 후 나는 테이블 (역할)에서 데이터 테이블이 데이터를 표시하고 난 행을 삭제하는 아약스 호출을 사용 :새로 고침 JQuery와 데이터 테이블 행

function OnDeleteClick(el) 
    { 
     //var url = ($(this).attr('href')); 
     //alert(url); 
     //var employeeId = event.getAttribute(id); //e.target.id 
     //var url = ($(this).attr('id'));  
     var id = $(el).attr('id');  
     var roleid = getURLParameter(id, 'id');   
     var username = getURLParameter(id, 'name');   
     var flag = confirm('You are about to delete Role ' + username + ' permanently.Are you sure you want to delete this record?'); 

     if (flag) { 
      $.ajax({ 
       url: '/Role/DeleteAJAX', 
       type: 'POST', 
       data: { roleId: roleid }, 
       dataType: 'json', 
       //success: function (result) { alert(result); $("#" + Name).parent().parent().remove(); }, 
       success: function (result) { 
        alert(result); 
       }, 
       error: function() { alert('Error!'); } 
      }); 
     } 
     return false; 
    } 

내 질문은 JQuery와 데이터 테이블 새로 고침하는 방법입니다 삭제가 성공하면 삭제 된 행도 데이터 테이블에서 삭제됩니까? 당신의 도움에 대한

<div class="row" > 
    <fieldset class="col-md-10 col-md-offset-1" > 
     <legend>Liste des rôles </legend> 
     <div class="table-responsive" style="overflow-x: hidden;"> 
      <table width="98%" class="table table-bordered table-hover" id="dataTables-example"> 
       <thead> 
        <tr> 
         <th>Designation Role</th> 
         <th></th> 
        </tr> 
       </thead> 
       <tbody> 
        @foreach (var item in Model) 
        { 
         <tr> 
          <td> 
           @item.Name 
          </td> 
          <td width="110">         
           <a class="btn btn-custom btn-xs" href="" onclick="return getbyID('@item.Id',false)" title="consulter"> 
            <i class="fa fa-folder-open-o"></i> 
           </a> 
           <a class="btn btn-custom btn-xs" href="" onclick="return getbyID('@item.Id',true)" title="Editer"> 
            <i class="fa fa-edit"></i> 
           </a> 
           <a class="btn btn-custom btn-xs" onclick="OnDeleteClick(this);" id="#[email protected]&[email protected]" title=" supprimer"> 
            <i class="fa fa-trash-o"></i> 
           </a> 
          </td> 
         </tr> 
        } 
       </tbody> 
      </table> 
     </div> 
     <div class="b-right"> 
      <button type="button" class="btn btn-primary" onclick="location.href='@Url.Action("Create", "Role")'"> 
       <i class="fa fa-plus"></i> Ajouter un role 
      </button> 
     </div>   
    </fieldset> 
</div> 

감사 : 아래

내가 내 JQuery와 데이터 테이블을 구축하는 데 사용하는 코드입니다.

+0

이는 HTML 테이블이며 jQuery를 사용하고 있습니다 :

var myTable = $("#myTable").DataTable({ ajax: "path/to/my/data" }); 

당신이처럼 새로 고칠 수 있습니까? 또는 DataTables https://datatables.net을 사용하고 있습니까? –

+0

그것은 간단한 HTML 테이블이 아닌 Jquery Datatables입니다. –

+0

테이블을 만드는 방법에 대한 코드를 표시 할 수 있습니까? –

답변

0

당신은 DataTables.net를 사용하는 경우와이 같은 테이블 내장 :

$.ajax({ 
    <your deleting code> 
    success: function() { 
     myTable.ajax.reload(); 
    }) 
}); 
+0

귀하의 답변을 주셔서 감사합니다 조하지만 실제로 내 datatable 귀하의 게시물에 내장되어 있지만 간단한 asp.net mvc보기를 사용하여. 그래서이 경우 어떻게 데이터 테이블을 새로 고칠 수 있습니까? –