2014-08-28 91 views
0

我正在努力使用Kendo UI獲得CRUD的功能嗎?我的創建和更新選項似乎不起作用,但我的閱讀確實有幫助嗎?我已經通過大量的教程,但只是不能得到這個工作。提前感謝。Php Kendo UI with datasource(CRUD)

這裏是我的代碼,這是我的index.php文件:

<!DOCTYPE html> 
<html> 
<head> 

<link href="styles/kendo.common.min.css" rel="stylesheet" /> 
<link href="styles/kendo.default.min.css" rel="stylesheet" /> 
<link href="styles/kendo.dataviz.min.css" rel="stylesheet" /> 
<link href="styles/kendo.dataviz.default.min.css" rel="stylesheet" /> 

<script src="js/jquery.min.js"></script> 
<script src="js/angular.min.js"></script> 
<script src="js/kendo.all.min.js"></script> 
</head> 
<body> 

<div id="example"> 
<div id="grid"></div> 
<script> 

    $(document).ready(function() { 
      dataSource = new kendo.data.DataSource({ 
       batch: true, 
       transport: { 

        read: "data/ussd.php" 
       }, 

       update: { 
        url: "data/ussd.php", 
        type: "POST" 
       }, 
       create: { 

        url: "data/create.php", 
        type: "PUT" 
       }, 
       parameterMap: function(options, operation){ 
        if(operation !== "read" && option.models){ 
         return{models : kendo.string(options.models)} 
        } 
       }, 

       pageSize: 20, 
       schema: { 
        data: "data", 
        model: { 
         id: "id", 
         fields: { 
          id: {editable: false, nullable: true}, 
          msisdn: {editable: true, type: "number"}, 
          company: {editable: true}, 
          description: {editable: true}, 
          ussd: {editable: true}, 
          updated: {editable: true, type: "date"}, 
          added: {editable: true, type: "date"} 
         } 
        } 
       }, 

       serverFiltering: true, 
       serverSorting: true 

      }); 

     $("#grid").kendoGrid({ 
      dataSource: dataSource, 
      pageable: true, 
      filterable: true, 
      sortable: true, 

      height: 500, 
      toolbar: ["create", "save", "cancel"], 
      columns: [ 

       { field: "id", title: "ID", width: "45px" }, 
       { field: "msisdn", title: "MSISDN", width: "75px" }, 
       { field: "company", title: "Company", width: "100px" }, 
       { field: "description", title:"Description", width: "100px" }, 
       { field: "ussd", title: "USSD", width: "100px" }, 
       { field: "updated", title: "Updated", width: "100px" }, 
       { field: "added", title: "Added", width: "100px" }, 
       { command: ["edit", "destroy"], title: "&nbsp;", width: "140px" }], 

      schema: { 
       model: { id: "id" } 
      }, 

      editable: "inline", 
      navigable: true 
     }); 


    }); 



</script> 
</div> 
</body> 
</html> 
+0

您batch''設置爲true時創建,更新和刪除將不會被調用,直到你的手段在Grid對象中調用'saveChanges'。你明確地調用它嗎?試着將'batch'設置爲'false'。 – OnaBai 2014-08-28 09:40:47

+0

謝謝,讓它以另一種方式工作。 – user2747477 2014-09-02 08:03:33

+0

你知道你可以回答你自己的問題嗎?如果您認爲您的解決方案是相關的,請執行此操作。否則,請刪除該問題,因爲它不會幫助其他人。 – OnaBai 2014-09-02 08:07:27

回答

0
{     read: "data/ussd.php" 
       }, 

       update: { 
        url: "data/ussd.php", 
        type: "POST" 
       }, 
       create: { 

        url: "data/create.php", 
        type: "PUT" 
       } 

你的閱讀和更新都使用相同的PHP文件。

什麼是PUT創建?

只需將更新url更改爲其他php文件並獲取發佈的值以在數據庫中運行查詢。 和改變也創造POST爲u使用POST別人太的類型..

在更新部分改變這種

url: "data/ussd.php", 

url: "data/update.php", 

,並試圖讓正如我之前所說的發佈值。看看是否適合你。

1

這是我改變,基本URL和類型不正確,不按正確的路徑

$(document).ready(function() { 

     dataSource = new kendo.data.DataSource({ 

      transport: { 

       read: "data/whitelist.php?type=read", 
       update: {url:"data/whitelist.php?type=update", type:"POST"}, 
       create: {url:"data/whitelist.php?=create",type:"POST"}, 
       destroy: {url:"data/whitelist.php?type=destroy",type:"POST"} 
      }, 


      batch: false, 
      pageSize: 20, 
      schema: { 

       model: { 
        id: "id", 
        fields: { 
         id: {editable: false, nullable: true}, 
         msisdn: {editable: true, type: "number"}, 
         company: {editable: true}, 
         description: {editable: true}, 
         ussd: {editable: true}, 
         updated: {editable: true, type: "date"}, 
         added: {editable: true, type: "date"} 
        } 
       } 
      }, 

      serverFiltering: true, 
      serverSorting: true 

     }); 

     $("#grid").kendoGrid({ 
      dataSource: dataSource, 
      pageable: true, 
      filterable: true, 
      sortable: true, 

      height: 430, 
      toolbar: [{name: "create", text: "Add New"}, "save", "cancel"], 
      columns: [ 

       { field: "id", title: "ID", width: "26px" }, 
       { field: "msisdn", title: "MSISDN", width: "50px" }, 
       { field: "company", title: "Company", width: "65px" }, 
       { field: "description", title:"Description", width: "65px" }, 
       { field: "ussd", title: "USSD", width: "50px" }, 
       { field: "updated", title: "Updated", width: "70px" }, 
       { field: "added", title: "Added", width: "70px" }, 
       { command: [{text:"Edit", name:"edit"}, {text:"Delete",name:"destroy"}], title: " ", width: "80px" }], 

      editable: "inline", 
      navigable: true 


     }); 
    });