2016-10-19 3 views
0

: 당신이 볼 수 있듯이실행 열 KendoGrid와 합 AngularJS와

enter image description here

열을 왼쪽은 바로 컬럼의 누적 합계가 포함되어 있습니다.

  1. 9435 + 956 = 10,391
  2. 9435 + 956 + 147 = 10,538
  3. 9435 + 956 + 147 + 694 = 11,232
예 :

나는 검도 그리드의 기초에 익숙하지만, 지금 당장이 일이 내게있다. 어디서부터 시작해야할지 모르겠다. 미리 감사드립니다.

답변

0

만약 당신이 그 값을 저장하고 싶은지 모르겠지만, 시각적 인 목적을 위해서라면, 컬럼을위한 템플릿으로 충분할 것입니다. 나는 시험에게 그것을 couldnt는

$scope.mainGridOptions = { 
    ... 
    columns: [ 
     { 
      title: "Running Sum", 
      template: function (dataItem) { 
       //This function is applied for each dataitem in your datasource 
       var dataSource=dataItem.parent();//Get the full dataSource 
       var index=dataSource.indexOf(dataItem);//Get the index of the dataItem in the dataSource 
       if(index>0){ 
        //Iterate to get the total 
        for(var i=0,total=0;i<=index;i++){ 
         total+=dataSource[i].Price; 
        } 
        return total; 
       } 
       else return dataItem.Price; 
      } 
     }, 
     ... 
    ], 
    ... 
}; 

하지만이 같은, 그리고만큼해야합니다

그리드의 컬럼의 정의에서, 당신은이처럼 "누적 합계"열을 정의해야합니다 당신은 당신의 데이터 소스에 수만개의 데이터 항목을 가지고 있지 않다. 당신의 성능은이 간단한 기능으로 손상되어서는 안된다. 나는 많은 가정

$scope.mainGridOptions = { 
    dataSource:{ 
     schema:{ 
      model:{ 
       ... 
       fields:{ 
        ... 
        Price:{type:"number",editable:true,defaultValue:0} 
        runningSum:{type:"number",editable:false,defaultValue:0} 
        //new property,dont worry for editable false, it will still allowed 
        //to be modified programatically and will be avoided 
        //in case of "editable":"popup" 
       } 
      } 
     } 
    }, 
    ... 
    columns: [ 
     { 
      title: "Running Sum", 
      template: function (dataItem) { 
       //This function is applied for each dataitem in your datasource 
       var dataSource=dataItem.parent();//Get the full dataSource 
       var index=dataSource.indexOf(dataItem);//Get the index of the dataItem in the dataSource 
       if(index>0){ 
        dataItem.runningSum=dataItem.Price + dataSource[index-1].runningSum; 
       } 
       else{ 
        dataItem.runningPrice=dataItem.price; 
       } 
       return dataItem.runningPrice 
      } 
     }, 
     ... 
    ], 
    ... 
}; 

:

그러나, 나는 그리드의 모델에 새로운 속성을 추가 고려할 것, 이전 요소의 단지 특성 "runningSum"를 읽어 (또는 당신은 그것을 이름을 무엇이든) 그리드 지시문처럼이 접근법에 대한 것들은 여러분이 내부에 모든 설정을 넣는 k-options = "mainGridOptions"를 가지고 있지만, 초안으로 당신에게 유용 할 수 있기를 바랍니다.