我在angular2中设置了ag-grid,它工作正常,但我无法获得所选行的值......我的控制台窗口中没有错误......这就是我初始化网格的方式......
import {Component} from 'angular2/core';
@Component({
selector: 'aggride',
template: `
<div class="tr-card" >
<ag-grid-ng2 #agGrid of mgrid class="ag-fresh" rowHeight="40px"
[columnDefs]="columnDefs"
[rowData] = "rowData"
enableCellExpressions="true"
enableSorting="true"
unSortIcon="true"
rowSelection="single"
(getSelectedRows) = "getSelectedRows()"
(onSelectionChanged) = "onSelectionChanged()"
>
</ag-grid-ng2>
</div>
`,
directives: [(<any>window).ag.grid.AgGridNg2],
})
这是我在类中获取所选值的代码
export class AgGride {
gridOptions = {
columnDefs: 'columnDefs',
rowData: 'rowData',
rowSelection: 'single',
getSelectedRows: 'getSelectedRows',
onSelectionChanged: 'onSelectionChanged'
};
columnDefs = [
{ headerName: "Make", field: "make", editable: true },
{ headerName: "Model", field: "model", editable: true },
{ headerName: "Color", field: "Color", editable: true }
];
rowData = [
{ make: "Toyota", model: "Celica", Color: "Red"},
{ make: "Ford", model: "Mondeo", Color: "Blue"},
{ make: "Tata", model: "X100", Color: "Blue"},
{ make: "Volvo", model: "X5", Color: "White"},
];
mgrid: any;
onSelectionChanged() {
var selectedRows = this.mgrid.ag.this.gridOptions.getSelectedRows();
console.log(selectedRows);
}
}
有人请告诉我如何纠正我的错误,以便我在控制台窗口中获取所选行的数据/值...