繁体   English   中英

Angular 2的Kendo-grid的RowEnter和RowLeave事件在哪里?

[英]Where are the RowEnter and RowLeave events of a kendo-grid for Angular 2?

在ODATA绑定的Kendo UI Angular 2表中,我必须满足保存用户通过按行而不是按单元格进行内联编辑更改的数据的要求。 如果有RowEnter和RowLeave事件,我可以这样做。

这些在哪

遗憾的是,没有这样的事件,但是,当网格的selectable属性设置为true时, 只要没有在kendo-grid-column-elements内放置任何ng-template-elements,就会触发selectionChange-event因此

<ng-template kendoGridCellTemplate let-dataItem>
    <input type="checkbox" [checked]="dataItem.Dropped?true:false" (click)="DroppedClicked($event, dataItem)" />
</ng-template>

此类模板未集成在编辑模式下,并且不会尊重用户交互,除非您将值明确写回到模型中,并手动检查该单元格是否与以前不在同一行中! 在其他情况下,您可以依赖selectionChange事件,该事件将在用户激活另一行的控件时触发。

为了从上述模板的input元素中识别行更改,click事件将事件变量和dataItem都传递给DroppedClicked-eventhandler,该处理程序将执行以下操作:

public DroppedClicked(event, dataItem): void
{
    let rowIndex = event.currentTarget.parentNode.parentNode.rowIndex;
    let arg = { crtlKey: null, deselectedRows: [this.currentRow], index: rowIndex, selected: true, selectedRows: [dataItem] };
    if (rowIndex != this.currentRowIndex) // row has changed
      this.onRowChange(arg);
    dataItem.Dropped = event.target.checked ? 1 : 0; 
}

其中onRowChange(...)是selectionChange-event的事件处理程序,已在网格的html模板中注册:

<kendo-grid projectAssignmentBinding [pageSize]="30"
            [pageable]="true" [filterable]="true" [selectable]="true" (selectionChange)="onRowChange($event)"
            [sortable]="true" [height]="500" editable="true" 
            (cellClick)="onEditCell($event)" (cellClose)="onCellClose($event)" >
    ...  
</kendo-grid>

然后该处理程序执行此操作:

  public onRowChange({ crtlKey, deselectedRows, index, selected, selectedRows }) : void
  {
    //alert("Row is changing!");
    if ( this.isDirtyRow )
        this.SaveRow();
    this.currentRow = selectedRows[0];
    this.currentRowIndex = index;
  }

使用SaveRow()保存this.currentRow并将this.IsDirtyRow重置为false。

使我最费力的是,接受编辑模式依赖于cellClick和cellClose事件中的cellwise开始和结束formGroup:无论列如何,cellClick必须开始一个新的formGroup,因为cellClose不会在其发布中发布columnIndex $ event,它将完全关闭整个formGroup。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM