Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Bootstrap Typeahead based on a CartoDB column
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Typeahead + CartoDB</title>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="well">
<input type="text" class="span3" id="filter" data-provide="typeahead" data-items="4" />
</div>
<script src="http://libs.cartocdn.com/cartodb.js/v2/cartodb.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js"></script>
<script>
var sql = new cartodb.SQL({ user: 'viz2', format: 'json'});
sql.execute("SELECT distinct name FROM d3_world_borders ORDER BY name").done(function(data){
var subjects = [];
for (var i = 0; i < data.rows.length; i++){
subjects.push(data.rows[i].name)
};
$('#filter').typeahead({source: subjects})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment