3

I have seen similar questions answered but I have not managed to find anything suitable.

I have some buildings and when I click on a building I want the name and website of the companies in it. I have thus a query that merges information from my buildings table and my companies table and this query often returns more than one row with multiple columns (at least company name and website).

I am trying to use the Custom HTML editor but when I use the Mustache tag to call the result, I only get the first row. How can I access the information in the next rows?

Note that I have also tried to use the aggregated strings as suggested somewhere else, but this is not good enough since I want also other columns and to decide the order and formatting... unless I can apply some string handling functions to it from the HTML, is this possible?

enter image description here

I have also seen some CartoDB.js, however this is used on the website that will display the map, but I do not have access to it. I will provide the cartoDB link so that the map is embedded in another website.

  • Could you give us a further example of the aggregated query you tried? You should be able to handle the strings on it directly. This is the only workaround, as CartoDB only knows about the "first row". – iriberri Feb 2 '15 at 9:21
  • The aggregated query is: SELECT string_agg(c.organisation, ',' ), b.the_geom_webmercator, b.cartodb_id from campuscompanies c, campusbuildings b where c.building_ref = b.building_ref group by b.the_geom_webmercator, b.cartodb_id – Paula Feb 2 '15 at 10:06
  • If this query retrieves the information that you showed in the screenshot, you'd just need to include in your query the rest of the columns you want to add. You can also apply some string s formatting by using Postgres functions. What is what you want to build finally? Could you provide a sample text for it? – iriberri Feb 2 '15 at 14:45
  • 2
    Thanks for your answers and time, I think in the end I am going to use the solution of templates and cartoDB.js, as it is the most flexible. – Paula Feb 3 '15 at 10:57
1

As we discussed in the comments, the approach would be aggregating the data in a single row. A more advanced workaround would be doing the query and then adding the results which are returned as JSON in a custom infowindow (this requires CartoDB.js), but the Mustache template only gets the first row associated to a geometry (it understands a geometry is just related with one row by default).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.