This is the same question as here: Cartodb - SQL query of public visualization of a private table
We have a private table and would like to use setSQL method to query the sublayer as we did with private data. I have created a basic template per documentation but what's next? Do I have to use this template instead of visualization? I can't get how the concept of the named maps and all that template stuff is related to the actual application code in Javascript. I have seen that you can have placeholder for SQL in the template but how is this placeholder filled from the application side in this case? We want to query by one or multiple fields. I just generated the code dynamically based on the filter object collecting values from UI elements (field1 and field2 are text and field3 is numeric with min and max values):
var filterFunction = function() {
////default query which is TRUE for all rows
newQuery = "SELECT * FROM mytable WHERE 1=1";
////collect filter parameters and append them to WHERE clause in SQL
if (filter.field1!="undefined"){
newQuery = newQuery + " AND field1='"+filter.field1+"'";
};
if (filter.field2!="undefined"){
newQuery = newQuery + " AND field2='"+filter.field2+"'";
};
if (filter.field3.min!="undefined"){
newQuery = newQuery + " AND field3>="+filter.field3.min;
};
if (filter.field3.max!="undefined"){
newQuery = newQuery + " AND field3<="+filter.field3.max;
};
////send query to the layer
sublayers[0].setSQL(newQuery);
return true;
};
So, how do we convert this to work with named map? I'm lost.