I have 3 layers(table_1,table_2,table_3) of data. In the info-window, which was created for the second layer.

I would like to display one column of data from table_1 . When I used {{table_1.name}}to display the data, I am getting the error , "Error in line 40: Cannot read property 'table_1' of undefined

Is there any way to display data from one table in another layer of data?

  • 1
    Sounds like you could use a SQL join in your main table to join columns from the other tables so that they become available for infoWindows. Do you have columns that can be joined to accomplish this? – DPSSpatial Aug 11 '14 at 15:22
  • @mapBaker : yes I have a comman column 'area_name' in both the tables. I used the SQL query 'Select table_2.hos_name,table_2.revenue from table_1,table_2 where table_1.area_name = table_2.area_name' in the info window editor but instead of the result the query itself is displayed as the value. I went through the tutorials yet I am missing something.Is there any way to include the query in the info-window editor ? Appreciate your help here. – Sowmya Aug 12 '14 at 9:43
  • sounds like you still have to configure the join between the two tables within the SQL window of one of them, or possibly create a new table that is a join of the two tables, so that you're not querying table1.fieldName and table2.fieldName, you're querying joinedTable.columnFromTableOne and joinedTable.columnFromTableTwo... know what I mean? – DPSSpatial Aug 13 '14 at 19:42

What about defining the template for your infowindow in your HTML code? Something like this

<script type="infowindow/html" id="infowindow_template">
    <div class="MyInfoWindowClass" id="MyInfoWindowID">
      <a href="#close" class="cartodb-popup-close-button close">x</a>
      <div class="cartodb-popup-content">
        <%= infowindow_content() %>
      <div class="cartodb-popup-tip-container"></div>

Then, in your js code (silly fields, just an example):

function infowindow_content(content)
   var field1;
   var field2;
   var field3;

   var sql = new cartodb.SQL({user: 'youruser'});

   // Add needed WHERE constraints here
   sql.execute("select t1.field1, t2.field2, t3.field from t1, t2, t3 WHERE ...")

    .done(function(data) {
       if (data.rows && data.rows.length) {
           // Fill field1, field2, field3 properly
           // example: field1 = data.rows[0].field1

   return "<div><p>" + field1 + + "</p><p>" + field2 + "</p><p>" + field3 + "</p></div>"; 

Not tested, but I think something like that should work.

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.