Angular2 ag-grid datasource not working

你说的曾经没有我的故事 提交于 2019-12-06 09:17:22

the data should be an array of data objects. my guess is your data is a string (of json). you need to convert the json to a data array.

Simon Azzopardi

Ok, I got it fixed as:

dataSource = {
    pageSize: 10,
    overflowSize: 100,

    getRows: (params: any) => {
        this.returnRows(params.startRow, params.endRow).subscribe(data => {
            var convertedDataToArray = JSON.parse(data);

             var lastRow = -1;

             params.successCallback(convertedDataToArray, lastRow);

        });
    }
}

I was getting the same error using React. This is the answer that pops up when looking for the error so I'll reply here since ag-grid is similar for both React and Angular.


In my case it was because I was trying to assign an object to the grid rather than an array. Because of Redux's immutability requirement I was doing this:

Object.assign({}, items)

when it should have been like this:

Object.assign([], items)

I just came across this issue. I am using "ag-grid-angular": "^18.1.0". Added onGridReady event to populate the grid data for which I added property (gridReady)="onGridReady($event)" in ag-grid-angular tag.

When I was trying to populate the data it was showing the error as mentioned above.

After trying few things I added agGrid: AgGridNg2; variable and imported the reference and it started working fine. Code spinet is as attached.

export class AppointmentComponent implements OnInit { @ViewChild('agGrid') agGrid: AgGridNg2;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!