2015-01-26 1 views
0
  • 목록 항목

나는 버튼을 눌러 검도 TreeList를로드하는 페이지가 있습니다. 데이터는 Kendo TreeList 데이터 소스의 기초로 남아있는 변수에 정적으로 정의 된 순간입니다.검도 사용자 정의 TreeList 설명서 추가 childNode에 예상치 못한 결과

Telerik 웹 사이트에서 주로 복사 한 데이터 소스 정의가 있습니다. 나는 CRUD의 관점에서 몇 가지 요구 사항을 가진 트리리스트를 보유하고 있습니다.

  • 수준 1 - 아무것도
  • 레벨 2 -

    CRUD 명령 버튼을 할 필요가 LEVEL3 항목을 더블 클릭한다 편집 및

편집 삭제 - 단지

  • LEVEL3 새로운 childNodes에 추가 아이콘 전용 (버튼에 텍스트 없음)

    나는 이것을 buildin으로 할 수 없었다. 불행히도 CRUD 컨트롤 그래서 나는 "유형"필드를 기반으로 버튼을 배치 템플릿 열을 사용.

    이제는 효과가 있었지만 어떻게 든 취소 할 수없는 일부 변경 사항 이후에 추가 기능이 더 이상 작동하지 않습니다. 그것은 작동하지만 새로운 노드는 다른 노드의 편집 또는 삭제 후에 만 ​​볼 수 있습니다. (마치 추가하는 동안 변경 이벤트가 트리거되지 않은 것처럼). treeList의 Add 버튼은 addProduct 함수를 호출합니다. 여기서 마지막으로 데이터 소스에 직접 pushCreate를 시도합니다. 그러나 Transport.create는 호출되지 않습니다. 그것은 단지 다른 후 발동한다 Crud action 그것이 방아쇠를 당긴다

    누군가 틀린 것을 볼 수있다. 그리고 이것 모두는 훨씬 쉬운 접근으로 달성 될 수 없었다?

    은 다음 페이지의 :

    <!DOCTYPE html> 
    <html> 
    <head> 
        <meta charset="utf-8" /> 
        <title>Kendo UI Grid - CRUD operations with local data</title> 
    
        <style> 
         html { 
          font-size: 12px; 
          font-family: Arial, Helvetica, sans-serif; 
         } 
        </style> 
        <link href="styles/kendo.common.min.css" rel="stylesheet" /> 
        <link href="styles/kendo.default.min.css" rel="stylesheet" /> 
    
        <script src="Scripts/jquery-2.1.3.min.js"></script> 
        <!--<script src="Scripts/kendo.all.min.js"></script>--> 
        <script src="Scripts/kendo.all.js"></script> 
    </head> 
    <body> 
        <style> 
         .hidden { 
          display: none; 
         } 
    
         .k-grid tbody .k-button, .k-ie8 .k-grid tbody button.k-button { 
          min-width: 0px; 
          padding-left: 10px; 
          padding-right: 0px; 
          padding-bottom: 0px; 
          padding-top: 0px; 
          margin: 0px; 
         } 
        </style> 
    
        <div id="buttons"> 
         <br /> 
         <p> 
          <button name="clear" id="clear" onclick="myclear()">Clear grid</button> 
          <button name="load" id="load" onclick="loadLocal()">Load from local DB</button> 
    
         </p> 
         <br /> 
         version 1.01<br /> 
         <br /> 
        </div> 
        <div id="treelist"></div> 
    
        <script id="btn-template" type="text/x-kendo-template"> 
         # if (Code == "Product") { # 
         <a id="btnupdate" class="k-button k-button-icontext k-grid-update column hidden" title="Update product" onclick="update(this)" href="\#"><span class="k-icon k-update"></span></a> 
         <a id="btndelete" class="k-button k-button-icontext k-grid-delete column" title="Delete product" data-command="destroy" href="\#"><span class="k-icon k-delete"></span></a> 
         # } else if (Code == "Requirement") { # 
         <a class="k-button k-button-icontext k-grid-add column" title="Add a product to this requirement" onclick="addProduct(this)" href="\#"><span class="k-icon k-add"></span></a> 
         # } # 
        </script> 
    
        <script> 
    
         var EPDdata // For holding the data of the TreeList 
    
    
         function loadLocal() { 
          EPDdata = [ 
              { Id: 1, Description: "Item1", Code: "Category", parentId: null }, 
              { Id: 2, Description: "Item2", Code: "Requirement", parentId: 1 }, 
              { Id: 3, Description: "Item3", Code: "Product", parentId: 2 }, 
              { Id: 4, Description: "Item4", Code: "Requirement", parentId: 1 }, 
              { Id: 5, Description: "Item5", Code: "Product", parentId: 4 }, 
              { Id: 6, Description: "Item6", Code: "Product", parentId: 4 }, 
              { Id: 7, Description: "Item7", Code: "Requirement", parentId: 1 }, 
              { Id: 8, Description: "Item8", Code: "Requirement", parentId: 1 }, 
              { Id: 9, Description: "Item9", Code: "Product", parentId: 8 }, 
              { Id: 10, Description: "Item10", Code: "Product", parentId: 8 } 
          ] 
          LoadTree(); 
         }; 
    
         function LoadTree() { 
          var EPDdataNextID = EPDdata.length + 1; 
    
          var LocaldataSource = new kendo.data.TreeListDataSource({ 
           transport: { 
            read: function (e) { 
             // on success 
             e.success(EPDdata); 
            }, 
            create: function (e) { 
             // assign an ID to the new item 
             e.data.Id = EPDdataNextID++; 
             // save data item to the original datasource 
             EPDdata.push(e.data); 
             // on success 
             e.success(e.data); 
            }, 
            update: function (e) { 
             // locate item in original datasource and update it 
             EPDdata[getIndexById(e.data.Id)] = e.data; 
             // on success 
             e.success(); 
            }, 
            destroy: function (e) { 
             // locate item in original datasource and remove it 
             EPDdata.splice(getIndexById(e.data.Id), 1); 
             // on success 
             e.success(); 
            } 
           }, 
           error: function (e) { 
            // handle data operation error 
            alert("Status: " + e.status + "; Error message: " + e.errorThrown); 
           }, 
           pageSize: 10, 
           expanded: true, 
           batch: false, 
           schema: { 
            model: { 
             id: "Id", 
             expanded: true, 
             fields: { 
              Id: { type: "number", editable: false, nullable: true }, 
              Description: { type: "string", validation: { required: true } }, 
              Code: { type: "string" }, 
              parentId: { type: "number", editable: true, nullable: true } 
             } 
            } 
           } 
          }); 
    
    
          $("#treelist").empty(); // only 1 treelist on the page please 
    
          $("#treelist").kendoTreeList({ 
           dataSource: LocaldataSource, 
           pageable: false, 
           edit: onEdit, 
           columns: [ 
            { field: "Description", title: "Description", width: "400px" }, 
            { field: "Code", width: "120px" }, 
            { field: "Id", title: "ID", width: "30px" }, 
            { field: "parentId", title: "PID", width: "30px" }, 
            { width: "35px", template: $("#btn-template").html() }, 
            { command: ["create", "edit", "destroy"] } 
    
           ], 
           editable: "inline" 
          }); 
    
          var treeList = $("#treelist").on("dblclick", function (e) { 
           var treeList = $("#treelist").data("kendoTreeList"); 
           var rowindex = e.target.parentNode.rowIndex; // get rowindex 
           var tr = $(e.target).closest("tr"); // get the current table row (tr) 
           var dataItem = $("#treelist").data("kendoTreeList").dataItem(tr); 
    
           if (dataItem.Code == "Product") { 
    
            $("#treelist").find(".edit").addClass("hidden"); 
            $("#treelist").find(".edit").removeClass("edit"); 
            $("#treelist").find(".delete").removeClass("hidden"); 
            $("#treelist").find(".delete").removeClass("delete"); 
    
            treeList.saveRow(); // first save all other rows 
            treeList.editRow(tr[0]); 
           }; 
          }); // double click function 
         }; // Function CreatetreeList 
    
         function onEdit(arg) { 
          var tr = $(arg.container);//.closest("tr"); // get the current table row (tr) 
          tr.find("#btndelete").addClass("hidden"); //remove btndelete from commandcolumn 
          tr.find("#btndelete").addClass("delete"); //put class to select the btn later on 
          tr.find("#btnupdate").removeClass("hidden"); //make btnupdate visible in commandcolumn 
          tr.find("#btnupdate").addClass("edit"); //put class to select the btn later on 
         }; 
    
         function update(e) { // update the edited row 
          var tr = $(e).closest("tr"); // get the current table row (tr) 
          var treeList = $("#treelist").data("kendoTreeList"); 
          treeList.saveRow(); 
          tr.find("#btndelete").removeClass("hidden"); 
          tr.find("#btndelete").removeClass("delete"); 
          tr.find("#btnupdate").addClass("hidden"); 
          tr.find("#btnupdate").removeClass("edit"); 
         }; 
    
         function addProduct(e) { 
          var treeList = $("#treelist").data("kendoTreeList"); 
          var dataSource = treeList.dataSource; 
          var data = dataSource.data; 
          var tr = $(e).closest("tr"); // get the current table row (tr) 
          var dataItem = treeList.dataItem(tr); 
    
          dataSource.pushCreate({ Id: 15, Description: "New", Code: "Product", parentId: dataItem.Id }); 
          alert("Done"); 
         }; 
    
         function getIndexById(id) { 
          var idx, 
           l = EPDdata.length; 
    
          for (var j; j < l; j++) { 
           if (EPDdata[j].Id == id) { 
            return j; 
           } 
          } 
          return null; 
         } 
        </script> 
    </body> 
    </html> 
    
  • 답변

    0

    내가 답을 발견!

    datasource pagesize가 10으로 설정되고 TreeList가 paging : false로 설정되었습니다. 모든 테스트에서 나는 10 노드의 샘플 데이터로 시작했다. 항상 다른 노드를 삭제할 때까지 표시되지 않는 11 번째와 12 번째 레코드를 추가하는 중 ...

    이러한 일이 나에게 일어날 수 있습니까?

    관련 문제