如何在Ag-grid的事件方法中使用javascript默认事件对象

时间:2019-01-29 07:43:56

标签: javascript angular ag-grid

我对ag-grid并不陌生,实际上我想在“ cellEditingStopped”网格事件中调用event.preventDefault(),但是我无法将默认的javascript事件对象传递给它。有什么办法可以实现?

此外,网格事件的对象也应该可用,因为它包含我需要用于数据库操作的行数据。

任何帮助将不胜感激。

以下是我的代码。

<ag-grid-angular
          id="timesheetInstructionGrid"
          [ngStyle] ="instructionsGridStyle"
          style="width: 100%;" 
          class="ag-theme-balham no-wrap"
          [rowData]="timesheetInstructionsRowData" 
          [columnDefs]="timesheetInstructionsColumnDefs"
          [frameworkComponents]="frameworkComponents"
          [singleClickEdit]="true"
          [defaultColDef]="defaultColDef"
          [pagination]="true"
          [enableColResize]="true"
          [stopEditingWhenGridLosesFocus]="true"
          [overlayNoRowsTemplate]="overlayInstructionsTemplate"
          (gridReady)="onInstructionsGridReady($event)"
          [rowSelection]="rowSelection"
          [rowDeselection]="'true'"
          (rowSelected) = "onInstructionsRowSelected($event)"
          (cellClicked) = "onInstructionsCellClicked($event)"
          (cellValueChanged) = "onCellValueChanged($event)"
          (cellEditingStopped) = "instructionGridCellEditDone($event)"
          [domLayout]="domLayout"
          >
      </ag-grid-angular>

1 个答案:

答案 0 :(得分:1)

您应该能够将该对象作为处理程序的参数本身。

看看我创建的小块:ag-Grid in Angular - event object with RowClicked event

打开控制台,然后单击任何行。我提供了rowClicked事件的示例。

onRowClicked($event: RowClickedEvent) {
  console.log($event.event)  ;
}

这就是我要登录的日志。

MouseEvent {isTrusted: true, screenX: -776, screenY: 239, clientX: 310, clientY: 210, …}
altKey: false
bubbles: true
button: 0
buttons: 0
cancelBubble: false
cancelable: true
clientX: 310
clientY: 210
composed: true
ctrlKey: false
currentTarget: null
defaultPrevented: false
detail: 1
eventPhase: 0
fromElement: null
isTrusted: true
layerX: 45
layerY: 94
metaKey: false
movementX: 0
movementY: 0
offsetX: 45
offsetY: 11
pageX: 310
pageY: 210
path: (23) [span, div.ag-cell.ag-cell-not-inline-editing.ag-cell-with-height.right-align.ag-cell-value.ag-column-hover…, div.ag-row.ag-row-odd.ag-row-level-0.ag-row-position-absolute.ag-row-hover.ag-row-focus.ag-row-selec…, div.ag-body-container.ag-layout-normal, div.ag-body-viewport.ag-layout-normal, div.ag-body-viewport-wrapper.ag-layout-normal, div.ag-body.ag-layout-normal.ag-row-no-animation, div.ag-root.ag-font-style.ag-layout-normal, div.ag-root-wrapper-body.ag-layout-normal, div.ag-root-wrapper.ag-layout-normal.ag-ltr, ag-grid-angular#div_0_ag-grid-angular_0.ag-theme-balham.ag-grid-row-hover-actions, div#div_0.ag-grid-container, im-ag-grid, div, mat-card.mat-card.ng-star-inserted, im-test-app-grid-config-svc.ng-star-inserted, ruf-app-canvas, div.ng-star-inserted, im-test-app-root, body.desktop, html, document, Window]
relatedTarget: null
returnValue: true
screenX: -776
screenY: 239
shiftKey: false
sourceCapabilities: InputDeviceCapabilities {firesTouchEvents: false}
srcElement: span
target: span
timeStamp: 29035.00000014901
toElement: span
type: "click"
view: Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
which: 1
x: 310
y: 210