2013-08-22 4 views
1

ASP.NET Web API에서 Kendo UI를 사용하고 있습니다. 필요한 모든 메소드를 가진 ProjectsController가 있습니다.Kendo UI DataSource가 transport.destroy를 트리거하지 않음

내 문제는 내가 Delete 버튼을 클릭하면, 검도 UI 그리드 remove() 이벤트를 발생시킬 것입니다,하지만 DataSource 결코 transport.destroy를 호출하지 않습니다. 오히려 tansport.create이 호출 된 것 같습니다. transport.parameterMap에서 대신이 아니라을 생성한다는 것을 알 수 있습니다. 요청이 피들러를 통해 발행 될 때

$(document).ready(function() { 
    var apiUrl = '/api/projects/'; 
    var dataType = 'json'; 

    var dataSource = new kendo.data.DataSource({ 
     batch: true, 
     autoSync: false, 
     transport: { 
      read: { 
       url: apiUrl, 
       dataType: dataType, 
       type: "GET" 
      }, 
      update: { 
       url: apiUrl, 
       dataType: dataType, 
       type: "PUT" 
      }, 
      destroy: { 
       url: apiUrl, 
       type: "DELETE" 
      }, 
      create: { 
       url: apiUrl, 
       contentType: "application/json;charset=utf-8", 
       dataType: dataType, 
       type: "POST" 
      }, 
      parameterMap: function (data, operation) { 
       console.log("Operation: " + operation); 
       if (operation === "create" && data.models) { 
        for (var i in data.models) { 
         var model = data.models[i]; 

         if (model.ProjectId === 0) { 
          return kendo.stringify(model); 
         } 
        } 
       } else if (operation === "destroy") { 
        console.log("Data.Models: " + data.models); 
        console.log("Data.id: " + data.ProjectId); 
        return { id: data.ProjectId }; 
       } 

       return data; 
      } 
     }, 
     schema: { 
      id: "ProjectId", 
      model: { 
       fields: { 
        ProjectId: { type: "number", editable: false, nullable: false, defaultValue: 0 }, 
        ProjectName: { type: "string", validation: { required: true } }, 
        Status: { type: "string", validation: { required: true } }, 
        IsActive: { type: "boolean" } 
       } 
      } 
     }, 
     pageSize: 10, 
     serverPaging: false, 
     serverFiltering: false, 
     serverSorting: false 
    }); 

    $("#projectsGrid").kendoGrid({ 
     dataSource: dataSource, 
     groupable: false, 
     sortable: true, 
     pageable: { 
      refresh: true, 
      pageSizes: true 
     }, 
     pageSize: 10, 
     toolbar: ["create"], 
     editable: "popup", 
     columns: [ 
      { field: "ProjectId", width: 30, title: "ID" }, 
      { field: "ProjectName", width: 180, title: "Project" }, 
      { field: "Status", width: 90, title: "Status" }, 
      { field: "IsActive", width: 40, title: "Is Active", type: "boolean", template: '<input type="checkbox" #if (IsActive) {# checked="checked" #}# disabled="disabled" />' }, 
      { command: ["edit", "destroy"], title: "&nbsp", width: "80px" } 
     ], 

     remove: function (e) { 
      console.log("Delete button clicked."); 
      console.log("Project ID: " + e.model.ProjectId); 
      //dataSource.remove(e.model); 
      //dataSource.sync(); 
     } 
    }); 
}); 

웹 API는 잘 작동하지만 검도 UI 그리드 보여줍니다 : 여기

은 샘플 자바 스크립트 코드

POST http://localhost:port/api/Projects 

DELETE을해야 할 때.

미리 감사드립니다.

답변

6

데이터 원본에 일괄 플래그가 true로 설정되어 있으면 데이터 소스는 사용자가이를 지정한 후에 만 ​​(예 : sync()를 호출 함을 의미합니다. http://docs.kendoui.com/api/framework/datasource#configuration-batch

뿐만 아니라

로 OnaBai 여기 Why does the KendoUI Grid Transport Create event gets raised multiple times, and even when the action is Update? 설명 된대로, 모델에 이드 정의했는지, 당신의 ID가 모델 외부이어야되어 있는지 확인 : 사람이있는 경우

model: { 
     id: "ProductID", 
     fields: { 
      ProductID: { editable: false, nullable: true }, 
     } 
    } 
+0

사실 실제로 그렇지 않습니다. 나는 (sync()를 호출하는지 또는'autoSync'가 true로 설정되었는지에 관계없이 웹 API에 대한 호출이 이루어지고 있음을 볼 수있다. 나는 batch를 false로 설정하려고 시도했으나 transport.create 문제는 삭제가'transport.destroy'를 발생시키지 않는다는 것인데, 아이템을 지울 때'transport.create'를 계속 올리는 것입니다. –

+0

코드에 아무 것도 보이지 않습니다.이 포스트를 보시오 OnaBai 's answer 당신이 정의하지 않은 것 같은 당신의 모델에서 ID의 요구 사항을 설명합니다 : http://stackoverflow.com/questions/16662223/why-does-the-kendoui-grid-transport-create-event-gets-raised-multiple-times - – Vojtiik

+0

고마워! 모델 내부에 ID를 추가하는 것은 해결책이다. –

4

위의 응답으로 idmodel에 정의했지만 아직 dataSource가 transport.destroy를 트리거하지 못해 구성하면 도움이 될 수 있습니다.

editable: { 
.. 
mode: "inline", //or "popup 
... 
} 
//or 
editable: "inline" //or "popup" 

http://www.telerik.com/forums/transport-destroy-of-grid-editor-is-not-working

+0

나도 마찬가지다. editable = false 일 경우 destroy가 실행되지 않을 것이다. +1 –

+0

Thanks Boss .. Watsed 3-4 이 문제에 대한 몇 시간 만에 .. – Coder