admin管理员组文章数量:1356067
I have an ag-Grid master/detail grid setup. So when the master grid row is expanded it then loads the detail grid.
See simple example:
This works on the basis that the data for the detail grid has already been fetched in the original json data used on the master grid.
I want to take the id
of the master grid selected row and make a 2nd HTTP service call to get the json data for the detail grid.
The simple example just sends the json data to the successCallback as follows:
getDetailRowData: function(params) {
params.successCallback(params.data.callRecords);
}
I have tried changing this method to:
getDetailRowData: function(params) {
this.http
.get(
".json"
)
.subscribe(data => {
params.successCallback(data);
});
// params.successCallback(params.data.callRecords);
}
With this code I get the following error(s):
ERROR TypeError: Cannot read property 'http' of undefined
ERROR Error: ag-Grid: cannot get grid to draw rows when it is in the middle of drawing rows. Your code probably called a grid API method while the grid was in the render stage. To overe this, put the API call into a timeout, eg instead of api.refreshView(), call setTimeout(function(){api.refreshView(),0}). To see what part of your code that caused the refresh check this stacktrace.
getDetailRowData: function(params) {
setTimeout(function() {
this.http
.get(
".json"
)
.subscribe(data => {
params.successCallback(data);
});
}, 500);
// params.successCallback(params.data.callRecords);
}
With this code I get the following error:
ERROR TypeError: Cannot read property 'get' of undefined
I have a Plunker:
Has anyone achieved lazy loading the detail grid data from a web API service call?
I have an ag-Grid master/detail grid setup. So when the master grid row is expanded it then loads the detail grid.
See simple example: https://www.ag-grid./javascript-grid-master-detail/#example-simple-master-detail
This works on the basis that the data for the detail grid has already been fetched in the original json data used on the master grid.
I want to take the id
of the master grid selected row and make a 2nd HTTP service call to get the json data for the detail grid.
The simple example just sends the json data to the successCallback as follows:
getDetailRowData: function(params) {
params.successCallback(params.data.callRecords);
}
I have tried changing this method to:
getDetailRowData: function(params) {
this.http
.get(
"https://gist.githubusercontent./adrianwright109/37a5e37ba2382b26f42b9d12a8593878/raw/60d2ffed511262a6a2e7e54e01bffd28c3701c5e/ClientProfiles.json"
)
.subscribe(data => {
params.successCallback(data);
});
// params.successCallback(params.data.callRecords);
}
With this code I get the following error(s):
ERROR TypeError: Cannot read property 'http' of undefined
ERROR Error: ag-Grid: cannot get grid to draw rows when it is in the middle of drawing rows. Your code probably called a grid API method while the grid was in the render stage. To overe this, put the API call into a timeout, eg instead of api.refreshView(), call setTimeout(function(){api.refreshView(),0}). To see what part of your code that caused the refresh check this stacktrace.
getDetailRowData: function(params) {
setTimeout(function() {
this.http
.get(
"https://gist.githubusercontent./adrianwright109/37a5e37ba2382b26f42b9d12a8593878/raw/60d2ffed511262a6a2e7e54e01bffd28c3701c5e/ClientProfiles.json"
)
.subscribe(data => {
params.successCallback(data);
});
}, 500);
// params.successCallback(params.data.callRecords);
}
With this code I get the following error:
ERROR TypeError: Cannot read property 'get' of undefined
I have a Plunker:
https://next.plnkr.co/plunk/IS5a3jKyDJJSSdh0
Has anyone achieved lazy loading the detail grid data from a web API service call?
Share Improve this question edited Jul 20, 2022 at 2:42 KARTHIKEYAN.A 20.2k10 gold badges137 silver badges150 bronze badges asked Apr 10, 2019 at 9:18 Adrian WrightAdrian Wright 1452 silver badges7 bronze badges3 Answers
Reset to default 6You need to use Arrow function like below
getDetailRowData: (params) => {
this.http
.get('.....')
.subscribe(data => {
params.successCallback(data);
});
Have a look at the updated plunk: https://next.plnkr.co/edit/t84UtB4kALFfAxO1
If you are using setTimeout
, then it should be like
getDetailRowData: (params) => {
setTimeout(() => {
this.http
.get('...')
.subscribe(data => {
params.successCallback(data);
});
}, 500);
// params.successCallback(params.data.callRecords);
}
Similar post: ag-grid server side infinite scrolling accessing props
We can directly call the api inside getDetailRowData
method and assign the values to params.successCallback()
method so that we will get the data in detail view
getDetailRowData: function(params) {
const payload = {searchParams: { id: Id }}
fetch('http://localhost:3000/get-Students', {
body: JSON.stringify(payload),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'POST',
})
.then(resp => resp.json())
.then(data => {
params.successCallback(data.rowData.map(rec => ({ ...rec, id: Id })))
})
.catch(e => {
console.log(e, 'error')
})
}
Well, in my case I kind of figured out that the "this" or the instance here is "undefined" inside the detailCellRendererParams, which is declared inside my ngOninit() function. Therefore, I declared a local variable inside the ngOninit with a name(say) temp and initiated it with the "this" at the beginning of the ngOninit() function like the following:
ngOninit() {
let temp_this: any = this;
//declaration of detailCellRenderer and stuff...
getDetailRowData: function(params) {
temp_this.http.get('..').subscribe(data=>{ // don't forget that this will
// work only if you have the HTTP dependency injection
// in your constructor else call a service using DI and subscribe it
params.successCallback(data);
}
}
}
It is remended to call your service methods, consisting of HTTP requests by adding your service's dependency injection in your ponent, unlike the above code. Anyhow, hope this helps you in understanding why we are getting this error.
本文标签: javascriptHow to make 2nd HTTP call to fetch data for detail gridgetDetailRowData()Stack Overflow
版权声明:本文标题:javascript - How to make 2nd HTTP call to fetch data for detail grid - getDetailRowData() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743974804a2570834.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论