admin管理员组文章数量:1334322
I have columns with the following values:
export class AppComponent {
private gridApi;
private gridColumnApi;
private columnDefs;
private rowData;
private defaultColDef;
private getRowNodeId;
constructor() {
this.columnDefs = [
{
headerName: "Make",
field: "make"
},
{
headerName: "Model",
field: "model"
},
{
headerName: "Price",
field: "price",
filter: "agNumberColumnFilter"
}
];
this.rowData = [
{
id: "aa",
make: "Toyota",
model: "Celica",
price: 35000
},
{
id: "bb",
make: "Ford",
model: "Mondeo",
price: 32000
},
{
id: "cc",
make: "Porsche",
model: "Boxter",
price: 72000
},
{
id: "dd",
make: "BMW",
model: "5 Series",
price: 59000
},
{
id: "ee",
make: "Dodge",
model: "Challanger",
price: 35000
},
{
id: "ff",
make: "Mazda",
model: "MX5",
price: 28000
},
{
id: "gg",
make: "Horse",
model: "Outside",
price: 99000
}
];
this.defaultColDef = {
editable: true,
sortable: true,
filter: true
};
this.getRowNodeId = function(data) {
return data.id;
};
}
How do I store the values in the 'Price' column into an array?
To clarify, I would like to have an array with the values from 'Price' - sort of like this:
var exampleArray = [35000,32000,72000,59000,35000,28000,99000]
(The full example, including the preview can be seen at the plunker link - )
I have columns with the following values:
export class AppComponent {
private gridApi;
private gridColumnApi;
private columnDefs;
private rowData;
private defaultColDef;
private getRowNodeId;
constructor() {
this.columnDefs = [
{
headerName: "Make",
field: "make"
},
{
headerName: "Model",
field: "model"
},
{
headerName: "Price",
field: "price",
filter: "agNumberColumnFilter"
}
];
this.rowData = [
{
id: "aa",
make: "Toyota",
model: "Celica",
price: 35000
},
{
id: "bb",
make: "Ford",
model: "Mondeo",
price: 32000
},
{
id: "cc",
make: "Porsche",
model: "Boxter",
price: 72000
},
{
id: "dd",
make: "BMW",
model: "5 Series",
price: 59000
},
{
id: "ee",
make: "Dodge",
model: "Challanger",
price: 35000
},
{
id: "ff",
make: "Mazda",
model: "MX5",
price: 28000
},
{
id: "gg",
make: "Horse",
model: "Outside",
price: 99000
}
];
this.defaultColDef = {
editable: true,
sortable: true,
filter: true
};
this.getRowNodeId = function(data) {
return data.id;
};
}
How do I store the values in the 'Price' column into an array?
To clarify, I would like to have an array with the values from 'Price' - sort of like this:
var exampleArray = [35000,32000,72000,59000,35000,28000,99000]
(The full example, including the preview can be seen at the plunker link - https://next.plnkr.co/edit/pS6575GNn6MliLBD )
Share Improve this question edited Jan 7, 2022 at 15:17 Jett asked Mar 11, 2019 at 14:07 JettJett 8802 gold badges17 silver badges36 bronze badges1 Answer
Reset to default 7I am afraid in the current way of getting all data from the AG-Grid is rather unintuitive. You have to do something like this if you wanna fetch the data from your ag-grid. Do not forget to initialise your gridApi within your ponent! On your ponent.html
<ag-grid-angular (gridReady)="onGridReady($event)" ... ></ag-grid-angular>
And on your ponent.ts,
onGridReady(params) {
this.gridApi = params.api;
}
.
.
getRowData() {
let rowData = [];
this.gridApi.forEachNode(node => rowData.push(node.data));
console.log(rowData)
}
In order to get an array of the prices, you can do this next:
const pricesArray = rowData.map(row => row['price']);
console.log(pricesArray);
本文标签: javascriptHow to create an array using values from columns in ag gridStack Overflow
版权声明:本文标题:javascript - How to create an array using values from columns in ag grid? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742356267a2459474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论