简体   繁体   English

在 ag-grid Angular 8 中重置固定底行数据

[英]Reset the Pinned Bottom Row Data in ag-grid Angular 8

I used pinned bottom row data as a Footer to display the summation of rows in AG-grid, but the problem is, I cant rest the value of pinned Row (the summation is a JSON Object contains the summation values that have been already calculated from Backend) .我使用固定底行数据作为页脚来显示 AG-grid 中行的总和,但问题是,我无法保留固定行的值(总和是一个 JSON 对象,包含已经从后端)

How could I resolve that without using Aligned Grid as Footer ?如果不使用对齐网格作为页脚,我该如何解决?

Note: the recived summation are not static will changed based on selected ID from drop down list注意:接收的总和不是静态的,将根据从下拉列表中选择的 ID 进行更改

this._myService.getProjectSummation("",[],selected,selected).subscribe(data=>{

  this.gridApi.setPinnedBottomRowData([]);
  this.gridApi.setPinnedBottomRowData(JSON.parse(data));


});

What I did similar to this Link but in my code, the pinned raw data values are not static it will change based on selected Option from Select我所做的与此链接类似,但在我的代码中,固定的原始数据值不是静态的,它会根据 Select 中选择的 Option 进行更改

Respond to the dropdown selection changes using the change event on <select> tag and then update your bottom pinned row based on your selection.使用<select>标记上的change事件响应下拉选择更改,然后根据您的选择更新底部固定行。 I have shown this using a simple total calculation of cart items in different currencies as example.我已经使用不同货币的购物车项目的简单总计算来展示这一点作为示例。

Template file:模板文件:

<h1>Ag Grid</h1>

<select (change)="calculateTotal($event)">
  <option 
    *ngFor="let item of currency" 
    [value]="item.name"
  >{{ item.name }}</option>
</select>

<ag-grid-angular 
  style="width: 95%; height: 250px" 
  class="ag-theme-balham" 
  [columnDefs]="columns" 
  [rowData]="rowData"
  (gridReady)="onGridReady($event)"
></ag-grid-angular>

Component file:组件文件:

  calculateTotal(event) {
    let ccyName = event.target.value;
    let ccy = this.currency.find(item => item.name === ccyName);

    this.gridApi.setPinnedBottomRowData([
      { product: `TOTAL (in ${ccy.name})`, price: this.total * ccy.factor }
    ]);
  }

Full example can be found here on the Stackblitz.完整的例子可以发现这里的Stackblitz。

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

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