I have a json done this way:
-entry (title, image, image, image, image)
-entry (title, image, image, image, image)
-entry …
I want to show title and first image in a grid. How can I achieve this? If i define a DataSource with title and image fields, the image value showed on the grid is “imageValue1,imageValue2,imageValue3,imageValue4”, while I only want “imageValue1”.
What I’m getting now is a grid with {“titleA”, “url0,url1”} in the first row and {“titleB”, “url2,url3”} in the second row because I’m using a Datasource with 2 fields:
one field with xPath = “title”
one field with xPath = “image/url”
Instead, I want a grid that shows {“titleA”, “url0”} in the first row and {“titleB”, “url2”} in the second row and so on if there are more entries.
As already pointed out, the JSON comes from a webservice, so I’m actually using a XJsonDataSource.
So basically, there are multiple URLs per entry but you only want to show the first. Use an XPath that ends in [0] for this, something like valueXPath:“image/url[0]” (note: haven’t tested this).
This is even worse: now it doesn’t get any value. I also tried image[0]/url, and it even get stuck on the “Getting data from server” window.
Can’t I modify the JSON before it is processed by the grid?
Or can’t I define another DataSource for the image, and then include the first url in the main DataSource? I’m just guessing here, I’m new to both Smart client and smartgwt.
Anyone can help here? I think that if this problem doesn’t have a solution, then that is a serious issue. Actually the JSON format provided in this thread is a semplification of the google api data feed, and not some exotic JSON API.
If there is no solution to this, I can always do this server side with php or java, but that is clearly the worst case, as it adds latency to the user request.
Thank you in advance.
“Read the docs for selectObjects”
That’s exactly what I needed! From the doc: “NOTE: in XPath, Array index starts at 1, not 0)”
So the right path was image/url[1].
Thanky you very much.