2016-11-30 3 views
0

私のAngularJSアプリケーションでは、剣道UIグリッドを使用しています。 私は以下の剣道UIグリッドオプションとデータソースを持っています。何をしようとしているのか何とか各行にクリックイベントを追加することです。私は各列の定義がありますが、列を含む行全体にはアクセスできません。これは、rowTemplateとaltRowTemplateを使用せずに可能ですか?私がそれらを使うなら、私は再びテーブル全体を再定義する必要があるからです。剣道UIグリッドを次の設定で選択しようとしています

HTML:

<div 
      k-options="ctrl.mainGridOptions" 
      k-rebind="ctrl.mainGridOptions" 
      kendo-grid="ctrl.gridInstance"> 
    </div> 

グリッドオプション:

this.mainGridOptions = { 
       dataSource: { 
        data: this.allRows, 
        pageSize: 150, 
        schema: { 
         model: { 
          fields: { 
           activityType: { type: "string" }, 
           communicationType: { type: "string" }, 
           count: { type: "number" }, 
          } 
         } 
        }, 
        aggregate: [ 
         { 
          field: "activityType", 
          aggregate: "count" 
         }, 
         { 
          field: "communicationType", 
          aggregate: "count" 
         }, 
         { 
          field: "count", 
          aggregate: "count" 
         } 
        ], 
        group: { 
         field: this.groupBy.field, 
         aggregates: [ 
          { 
           field: "activityType", 
           aggregate: "count" 
          }, 
          { 
           field: "communicationType", 
           aggregate: "count" 
          }, 
          { 
           field: "count", 
           aggregate: "count" 
          } 
         ] 
        } 
       }, 
       scrollable: { 
        virtual: true 
       }, 
       sortable: true, 
       resizable: false, 
       pageable: false, 
       groupable: true, 
       columnMenu: true, 
       filterable: true, 
       reorderable: false, 
       columns: [ 
        { 
         headerTemplate: '<md-checkbox ng-model="dataItem.checked" ng-change="ctrl.headerSelected(dataItem)" aria-label="row check" ng-transclude=""></md-checkbox>', 
         template: '<md-checkbox stop-event ng-class="{\'row-selected\' : ctrl.checkVisible.length > 0 || ctrl.headerCb}" ng-model="dataItem.checked" ng-change="ctrl.rowSelected(dataItem, dataItem.cbIndex)" aria-label="item check"></md-checkbox>', 
         width:"50px" 
        }, 
        { 
         field: "activityType", 
         title: "activityType", 
         aggregates: ['count'], 
         template: '<span ng-bind="dataItem.activityType"></span>', 
         groupHeaderTemplate: '<span class="aggregate-wrapper" ng-click="ctrl.toggleGroupCollapse($event)"><span>' + "activityType" + ':' + '</span>' + ' #= value # (Count: #= count#)</span>' 
        },{ 
         field: "communicationType", 
         title: "communicationType", 
         aggregates: ['count'], 
         groupHeaderTemplate: '<span class="aggregate-wrapper" ng-click="ctrl.toggleGroupCollapse($event)"><span>' + "communicationType" + '</span>' + ' #= value # (Count: #= count#)</span>' 
        },{ 
         field: "count", 
         title: "count", 
         aggregates: ['count'], 
         template: '<div layout="row" layout-align="center center">' + 
         '<md-progress-linear flex="80" md-mode="determinate" ng-value="ctrl.calcProgressValue(dataItem.count)"></md-progress-linear>' + 
         '<span flex style="text-align:right" ng-bind="dataItem.count"> </span>' + 
         '</div>', 
         groupHeaderTemplate: '<span class="aggregate-wrapper" ng-click="ctrl.toggleGroupCollapse($event)"><span>' + "count" + ':' + '</span>' + ' #= value # (Count: #= count#)</span>' 
        }, 
        { 
         field: "", 
         title: null, 
         template: '<span class="action-controls"><i class="material-icons">label</i><i class="material-icons">star_rate</i><i class="material-icons"> more_vert </i></span>', 
         width: '200px' 
        } 
       ], 
      }; 

これは、私はあなたが使用トリガーされchange eventを、使用することができ剣道グリッドに

this.allRows = [ 
{ 
     "activityType": 2, 
     "activitySubType": 10, 
     "count": 265 
     }, 
     { 
     "activityType": 2, 
     "activitySubType": 1, 
     "count": 238 
     }, 
     { 
     "activityType": 7, 
     "activitySubType": 3, 
     "count": 102 
     }, 
     { 
     "activityType": 6, 
     "activitySubType": 12, 
     "count": 142 
     }, 
     { 
     "activityType": 6, 
     "activitySubType": 18, 
     "count": 98 
     }, 
     { 
     "activityType": 2, 
     "activitySubType": 19, 
     "count": 145 
     } 
]; 
+0

私は自分自身を明確にしてみましょう..あなたが望むすべてがすべての行にクリックイベントがあり、上のあなたが行全体のデータを必要とする]をクリックすることです。..右? –

+0

正確にクリックしてスコープ変数を変更し、その行のng-classでそのクラスを変更します –

+0

角度のあるものは認識していません。クリックをコントロールして行データを取得します。あなたはそこから続行する必要があります –

答えて

1

を渡すデータでありますグリッド内の行またはセルをtに変更します。彼selectableオプションがtrueに設定されています:

change: function() { 
    // Get your row's data 
    var dataItem = this.dataItem(this.select()); 
} 

Demo

+0

それは動作しますが、なぜ私は最初の行が選択されていない取得する2番目の行を選択することができません –

+0

私はちょうど行がクリックされたときに関数を呼び出す。 selectable: "multiple、row"を使用すると、2番目の行を選択するためにctrlを押す必要があります。 –

+0

@GeorgiAntonovは、行をクリックしたときに*関数*を呼び出すだけで、イベント内で呼び出す必要があります。 Ctrlキーを使用せずに複数の行を選択するには、カスタムコードを使用する必要があります。 – DontVoteMeDown

関連する問題