简体   繁体   中英

ag-grid with simple type row data

I am having a hard time setting up an ag-grid table in an Angular 6.0 application where the row data model is a an array of simple types (dates, numbers, strings, etc.)

The only way I can do so is to wrap the all the data into an object list (each object containing a single property) and pass it as the row data. It also means that I have to manually and systematically have to unwrap the data whenever I need to access it.

To put it differently, is there a way to define a columnDef without a field in ag-grid table and having it consider implicitly that the field data is the entire row data?

var gridOptions = {
    columnDefs: [
        {headerName: 'Athlete'}
    ],
    rowData: ['John', 'Oliver']
}

I think field is required but colId is not required (it will default to the field). Field is what maps a column to the data set. Here are more details about column definitions .

It may be easier to edit your data before initializing the grid. Something like this may work:

var data = ['John', 'Oliver'].map(name => {return {name} });
var gridOptions = {
    columnDefs: [
        {field:'name', headerName: 'Athlete'}
    ],
    rowData: data
}

You can config your columnDefs

var gridOptions = {
    columnDefs: [
        {
            headerName: 'Athlete',
            valueGetter: (node) => node.data
        }
    ],
    rowData: ['John', 'Oliver']
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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