gpt4 book ai didi

angularjs - Ag-Grid 需要每一行的删除按钮

转载 作者:行者123 更新时间:2023-12-01 01:49:29 24 4
gpt4 key购买 nike

我正在尝试使用 ag-grid 实现解决方案并且没有陷入问题。我正在尝试在每一行中实现编辑和删除按钮。编辑按钮实现成功,但问题在于删除按钮。我已尽我所能(这对于 angular 2 来说很少)。请按照下面的代码查看实现:-

法院组件.ts

import { Component } from '@angular/core';
import { Court } from './court.model';
//import './../utils/array.extensions';

import { GridOptions } from "ag-grid";
import { DataCourtService } from '../services/data-court.service';
import { EditButtonComponent } from "../utils/editbutton.component";

@Component({
selector: 'court',
template: require('./court.component.html'),
providers: [DataCourtService]
})

export class CourtComponent {
private gridOptions: GridOptions;
public courts : Court[];
onQuickFilterChanged(event: any) {
this.gridOptions.api.setQuickFilter(event.target.value);
}
constructor() {
var courtservice = new DataCourtService();
this.gridOptions = {
rowSelection: 'single'
};

// this.gridOptions.angularCompileRows = true;
this.gridOptions.columnDefs = [

{
headerName: "Court Name",
field: "courtname",
editable: true
} ,
{
headerName: "Action",
cellRendererFramework: EditButtonComponent,
colId: "edit"
}

];

this.gridOptions.rowData = courtservice.getCourt();

}
}

编辑按钮.component.ts
import {Component} from "@angular/core";
import {ICellRendererAngularComp} from "ag-grid-angular/main";

@Component({
selector: 'edit-button',
template: `<button (click)="invokeEditMethod()" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-edit"></span>Edit</button>
<button (click)="invokeDeleteMethod()" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove"></span>Delete</button>`
})
export class EditButtonComponent implements ICellRendererAngularComp {
public params: any;

agInit(params: any): void {
this.params = params;
}
public invokeDeleteMethod() {
var selectedData = this.params.api.getSelectedRows();
this.params.api.updateRowsData({remove: selectedData});
alert("hi");

}
public invokeEditMethod() {


this.params.api.setFocusedCell(this.params.node.rowIndex, 'courtname');
this.params.api.startEditingCell({
rowIndex: this.params.node.rowIndex,
colKey: 'courtname',
}
);
}

}

在这个函数中
public invokeDeleteMethod() {
var selectedData = this.params.api.getSelectedRows();
this.params.api.updateRowsData({remove: selectedData});
alert("hi");

}

我收到一个错误,因为 UpdateRowData 不是一个函数。你能帮我实现这个吗??

最佳答案

这个功能是在 aggrid 10+ 中引入的,我正在使用 8+。更新它解决了这个问题。

关于angularjs - Ag-Grid 需要每一行的删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45686884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com