jQuery UI Widgets › Forums › Grid › The loadedData property
Tagged: adapter, ajax, grid, jqxAdapter, jqxgrid, json, loadedData, response
This topic contains 6 replies, has 3 voices, and was last updated by fritzfrancis 9 years, 3 months ago.
-
AuthorThe loadedData property Posts
-
Hello,
My application recently required me to be able to access the original JSON response that my jqxGrid’s data adapter received in the AJAX call. It wasn’t until I discovered the source object’s loadedData property that I was able to achieve my goal.
Here is an example of my selector:
$("#jqxGrid").jqxGrid("source").loadedData
As I was unable to find anything in the jqxGrid or jqxAdapter documentation that mentions the loadedData property, I’d like to know if there’s a reason I should not be using it, or if there’s some other way to get to that data through an officially supported method.
If there are no drawbacks to using the loadedData property, perhaps some documentation should be added so that others can utilize this very helpful property.
Regards,
Fritz FrancisHi fritzfrancis,
I would suggest you to do not use internal properties. The dataAdapter’s records property which is an Array is enough for any use of jqxDataAdapter.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Peter,
In my case, using the
records
property was not enough because my dataAdapter’s source URL returns a JSON object that contains more than just an array of my grid data. For instance, let’s say my dataAdapter’s source URL is “/Home/GridJSON”. It returns a JSON object that’s shaped like this:{ ClickOpensNewTab: bool, GridData: Array[n], IsSuccessful: bool, StatusMessage: "" }
As you can see, the JSON object itself isn’t what the grid binds to. Rather, the
GridData
property inside the JSON object is what it binds to. So in this case,loadedData
andrecords
will not be identical. TheloadedData
property will give me the whole JSON object, whereas therecords
property will only give me the array.This brings up a question: how does the jqxDataAdapter/jqxGrid know to use my GridData array, rather than trying to bind to the whole JSON object and failing? Does it just look for the first array inside the JSON and use that?
Regards,
Fritz FrancisHi fritzfrancis,
There is mapping, record and root settings in the adapter’s source object which point where the data array is.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Thanks for your quick reply.
I’m not quite sure how those properties relate to the question, because in my object, both
record
androot
are blank strings. So I’m still wondering how it knows to use theGridData
array rather then the whole JSON object.Hi fritzfrancis,
It knows what is Array and what is not.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/That makes sense. So, if it has the ability to look at only the array inside the JSON object, then putting extra information in the JSON object and referring to it using
loadedData
seems like a very standard use case. I think other developers would find this functionality very useful, and thatloadedData
is an excellent candidate to be made into an officially documented property. -
AuthorPosts
You must be logged in to reply to this topic.