Build/Rebuild grid from JSON response
-
- Profound User
- Posts: 36
- Joined: Fri Jul 17, 2020 12:52 pm
- First Name: Jason
- Last Name: Guzik
- Company Name: 3Linc
- Contact:
Build/Rebuild grid from JSON response
Is it possible to build and rebuild a grid from an AJAX JSON response?
I am making an API call that returns a JSON object. This API gets called often to keep the data as real time as possible. Is there a way to take that JSON response and clear/build the grid over and over? If not, do you have a suggestion I can look into?
Thanks
I am making an API call that returns a JSON object. This API gets called often to keep the data as real time as possible. Is there a way to take that JSON response and clear/build the grid over and over? If not, do you have a suggestion I can look into?
Thanks
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Build/Rebuild grid from JSON response
Yes.
The easiest way to do this would be to use the "data url" property to load the grid. This will call a URL (ajax request) and load the response (if properly formatted) into the grid. This can be used in conjunction with any of the "database-driven" grid functionality (even though you're not using a database directly) including the "load fields into widgets" and "load all rows" properties.
Calling the grid's grid.refresh() method will cause it to re-run the URL, so you can do that on a timeout or interval if you want.
The other way to do it is to do a traditional Ajax request and update the grid via the setDataValue() API. This would require a bit more work and it probably wouldn't perform as fast, but would make it possible to interact with backend code, such as an RPG program, if needed.
The easiest way to do this would be to use the "data url" property to load the grid. This will call a URL (ajax request) and load the response (if properly formatted) into the grid. This can be used in conjunction with any of the "database-driven" grid functionality (even though you're not using a database directly) including the "load fields into widgets" and "load all rows" properties.
Calling the grid's grid.refresh() method will cause it to re-run the URL, so you can do that on a timeout or interval if you want.
The other way to do it is to do a traditional Ajax request and update the grid via the setDataValue() API. This would require a bit more work and it probably wouldn't perform as fast, but would make it possible to interact with backend code, such as an RPG program, if needed.
-
- Profound User
- Posts: 36
- Joined: Fri Jul 17, 2020 12:52 pm
- First Name: Jason
- Last Name: Guzik
- Company Name: 3Linc
- Contact:
Re: Build/Rebuild grid from JSON response
Thanks Scott. I'll give it a go tomorrow.
Looked at the docs. All i need to do is match up my response with the binded values? At least that is what it looked like at first glance. Should be a fun learning experience
Looked at the docs. All i need to do is match up my response with the binded values? At least that is what it looked like at first glance. Should be a fun learning experience
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Build/Rebuild grid from JSON response
How you do it depends on which of the above options you've chosen to use.
- With a data url and the "load fields into widgets" option, then you need to match the bound field names.
- With a data url, but without "load fields into widgets", the format of the JSON has to be correct, but the names of the fields are ignored.
- With a traditional ajax approach, the format of your JSON is up to you, but the calls to setDataValue have to specify the proper bound field names.
-
- Profound User
- Posts: 36
- Joined: Fri Jul 17, 2020 12:52 pm
- First Name: Jason
- Last Name: Guzik
- Company Name: 3Linc
- Contact:
Re: Build/Rebuild grid from JSON response
Brilliant. Thank you!
-
- Profound User
- Posts: 36
- Joined: Fri Jul 17, 2020 12:52 pm
- First Name: Jason
- Last Name: Guzik
- Company Name: 3Linc
- Contact:
Re: Build/Rebuild grid from JSON response
So I have this working, sort of. I am using the data url and my JSON matches the bound field values. The only thing I notice is that my grid is part of a larger dashboard, and the amount of rows is limited to 8 based on the amount of space I have on the page. My JSON returns 9 totalRecs. However the grid is only showing the first 8 records. When I scroll it doesn't get to the last record.
Code: Select all
{
"success":true,
"response": {
"results":[{
"agentName":"Person A",
"agentState":"Inbound Contact",
"agentTime":"1:17"
},{
"agentName":"Person B",
"agentState":"Available",
"agentTime":"3:19"
},{
"agentName":"Person C",
"agentState":"Unavailable: Lunch",
"agentTime":"4:24"
},{
"agentName":"Person D",
"agentState":"Available",
"agentTime":"6:31"
},{
"agentName":"Person E",
"agentState":"Available",
"agentTime":"17:02"
},{
"agentName":"Person F",
"agentState":"Available",
"agentTime":"20:19"
},{
"agentName":"Person G",
"agentState":"Available",
"agentTime":"23:30"
},{
"agentName":"Person H",
"agentState":"Unavailable: Lunch",
"agentTime":"30:38"
},{
"agentName":"CANNOT BE SEEN",
"agentState":"Logged Out",
"agentTime":""
}],
"totalRecs":9
}
}
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Build/Rebuild grid from JSON response
Are you using the "load fields into widgets" property? Have you enabled the "load all" property?
When I asked this before, you figured out the answer, but never told me which properties you were using. If you wouldn't mind letting me know, that'll make it much easier to answer any future questions you have.
When I asked this before, you figured out the answer, but never told me which properties you were using. If you wouldn't mind letting me know, that'll make it much easier to answer any future questions you have.
-
- Profound User
- Posts: 36
- Joined: Fri Jul 17, 2020 12:52 pm
- First Name: Jason
- Last Name: Guzik
- Company Name: 3Linc
- Contact:
Re: Build/Rebuild grid from JSON response
I don't have that option. I'm just using data url and i build a json response that matches the bound values. Data Url is the only option i see actually.
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Build/Rebuild grid from JSON response
If you don't have those options, you're running an old version of Profound UI (prior to ver 6, fix pack 9, which was released in October 2020).
In that case
In that case
- It doesn't matter if the field names match, because the grid won't use the field names. It simply loads the first field into the first grid column, the second into the second grid column, etc. It won't use any widgets you placed on the grid at all.
- It will always load one page at a time. When your data url is called, it will pass parameters named 'start' and 'limit' telling you which page of data to return. You will need to provide the correct records for that page.
-
- Profound User
- Posts: 36
- Joined: Fri Jul 17, 2020 12:52 pm
- First Name: Jason
- Last Name: Guzik
- Company Name: 3Linc
- Contact:
Re: Build/Rebuild grid from JSON response
Oh wow. Got it.
I'm running v6 fix pack 7.1
I will contact admin to see about upgrading
Thanks
I'm running v6 fix pack 7.1
I will contact admin to see about upgrading
Thanks
Who is online
Users browsing this forum: Ahrefs [Bot] and 0 guests