Skip to content

Instantly share code, notes, and snippets.

@andrewxhill
Created March 15, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewxhill/5171504 to your computer and use it in GitHub Desktop.
Save andrewxhill/5171504 to your computer and use it in GitHub Desktop.
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