2016-04-12 12 views
1

KendoGrid veri tablosu eklentisi yardımıyla bir tablo oluşturdum ve silme tablosunun yeniden yüklenmesinden sonra silme işlemini gerçekleştirdim ve silinen kullanıcıyı göstermesin ancak tabloyu yeniden yüklediğimde tabloyu yeniden göstermiyor ve yine de tabloyu gösteriyorum. sayfası kullanıcı bilgilerini ı aşağıdaki kodu yorgun gelmiş ama not çalışmıyor gitmiş olacak: silme işlemi düzgünjquery, sayfayı yenilemeden tabloyu nasıl yenileyebilir?

<head> 
    <script> 
     $(function() { 
      $("#example").dataTable(); 
     }) 
    </script> 
    <script> 
     $(document).ready(function() { 
      $("#example").kendoGrid({dataSource: { 
        pageSize: 10 
       }, 
       editable: "popup", 
       sortable: true, 
       filterable: { 
        extra: false, 
        operators: { 
         string: { 
          contains: "Contains", 
          startswith: "Starts with" 
         } 
        } 
       }, 
       pageable: true, 
      }); 
     }); 
    </script> 

    <script> 
     function deleteuser(obj) { 
      var uid = obj.id; 
      var uname = obj.name; 
      if (confirm("This user '" + uname + "' maybe using some other events, Are you sure to delete this user?")) { 


       if (window.XMLHttpRequest) { 
        xmlhttp = new XMLHttpRequest(); 
       } else { 
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 

       xmlhttp.onreadystatechange = function() { 
        //alert(xmlhttp.responseText.trim()); 
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
         //alert(xmlhttp.responseText.trim()); 
         if (xmlhttp.responseText.trim() == 'deleted') { 
          alert('This user "' + uname + '" succesfully deleted'); 
$('#example').data('kendoGrid').dataSource.read(); 
         } else 
          alert('Error : user cannot deleted'); 

        } 
       } 
       var url = "deleteuser.php?id=" + uid; 
       xmlhttp.open("GET", url, true); 
       xmlhttp.send(); 

      } 
     } 
    </script> 
</head> 

<body> 
    <div> 
     <table id="example"> 
      <thead> 
       <tr> 
        <td>Action</td> 
        <td>Name</td> 
        <td>Username</td> 
        <td>Email</td> 
       </tr> 
      </thead> 
      <tbody> 
       <?php 
       $sql = "SELECT * from registration"; 
       $result = $conn->query($sql); 
       while ($row = $result->fetch_assoc()) { 
        ?> 
        <tr> 
         <td><button class="btn btn-danger btn-xs" id="<?php echo $row['user_id'] ?>" onClick="deleteuser(this);" name="<?php echo $row['first_name'] ?>" title="Delete"><i class="fa fa-trash-o"></i></button></td> 
         <td><?php echo $row['first_name'] ?></td> 
         <td><?php echo $row['user_name'] ?></td> 
         <td><?php echo $row['email'] ?></td> 

         <?php 
        } 
        ?> 
       </tr> 
      </tbody> 
     </table> 
    </div> 
</body> 

deleteuser.php

<?php 
    session_start(); 
    $id = $_GET['id']; 
    include("../model/functions.php"); 
    $table = "registration"; 
    $condition = "user_id=" . $id . ""; 
    $delete = Deletedata($table, $condition); 

    if ($delete === TRUE) { 
     echo'deleted'; 
    } else { 
     echo 'not deleted'; 
    } 
?> 
+0

, böylece yenilemek için hiçbir şey yoktur. – whipdancer

cevap

1
çalışıyorTablo verilerini, tabloyu verileri nereden aldığını tanımladığınızdan güncelleştiremezsiniz. Can tüm sayfayı yenileyebilir veya verileri almak için kullanabileceğiniz bir transport & url ile bir datasource oluşturun.

tablo sunucu tarafı doldurmak Ne zaman:

<tbody> 
    <?php 
    $sql = "SELECT * from registration"; 
    $result = $conn->query($sql); 
    while ($row = $result->fetch_assoc()) { 
     ?> 
     <tr> 
      <td><button class="btn btn-danger btn-xs" id="<?php echo $row['user_id'] ?>" onClick="deleteuser(this);" name="<?php echo $row['first_name'] ?>" title="Delete"><i class="fa fa-trash-o"></i></button></td> 
      <td><?php echo $row['first_name'] ?></td> 
      <td><?php echo $row['user_name'] ?></td> 
      <td><?php echo $row['email'] ?></td> 

      <?php 
     } 
     ?> 
    </tr> 
</tbody> 

tablo yenilemek için bir şey yok.

Verileri almak için tabloya veri kaynağı eklemeniz gerekir.

Genel olarak, ızgara tanımı veri kaynağının kendisinden ayrı olarak tanımlarım. Örnek olarak

:

var gridDataSource = new kendo.data.DataSource({ 
    transport: { 
     read: { 
      url: "someurl/to/my/data" 
     } 
    }, 
    schema: { 
     model: { id: "user_id" } 
    } 
}); 

Sonra böyle masa şey tanımlayabilirsiniz: Eğer Kendo Grid ile bir veri kaynağı kullanmıyorsanız

var jgrid = $("#example").kendoGrid({ 
    columns: [ 
     { 
      field: "first_name", 
      title: "First Name" 
     }, 
     { 
      field: "user_name", 
      title: "User Name", 
     }, 
     { 
      field: "email", 
      title: "Email" 
     } 
    ], 
    dataSource: gridDataSource 
}).data("kendoGrid"); 
0
$('#GridName').data('kendoGrid').dataSource.read(); 
$('#GridName').data('kendoGrid').refresh(); 
+0

bunu denedi ama çalışmıyor –

İlgili konular