thinkmap.graph.autocomplete.Autocomplete

Jump To: Members Events

A class that binds autocomplete functionality to a graph and text field. Autocomplete works by popping open a result set of queries that are performed each time a user enters text into the text field. These queries will hit the remote datasource of a graph and results will be returned, upon which, they will be rendered directly below the text field.

When using autocomplete, it is important to override the buildQuery and renderItem methods as they will not be suitable for most projects by default.

Also, one should add styling to the autocomplete list which uses the css class name _tm_autocomplete_

Examples:

Create autocomplete for the default movie example var graph = new thinkmap.graph.Graph(); // autocomplete should be used with a graph that has a remote datasource graph.datasource('server.tas'); var autoComplete = new thinkmap.graph.autocomplete.Autocomplete(graph, document.getElementById('search') ); // when a user selects an item call this function autoComplete.on('select', makeCenter); // define the query that the autocomplete will use autoComplete.buildQuery = function(search) { if (search.length) { if (!/["'*:?]/.test(search)) { search = search.trim().split(/\W/).join(' AND ')+"*"; } return {$t:'node', $search:search}; } return null; }; autoComplete.renderItem = function( itemSelection, result ) { var data= result.entity.data; var text = null; if(result.entity.isType('movie')){ text = data.title + ' ('+data.year+')'; } else if(result.entity.isType('person')){ text = data.firstname + ' ' + data.lastname; } else if(result.entity.isType('genre')){ text = data.genrename; } itemSelection.append('span').text(text ); };

Constructor

Instance Methods

Events

This event is fired each time an item is selected in the autocomplete. The single argument is the entity.

update : function ( thinkmap.graph.traversal.ResultSet )

This event is fired each time the autocomplete is to be updated by a new result set from a query

hide : function ( )

This event is fired when the autocomplete becomes hidden

clear : function ( )

This event is fired when the autocomplete's results have been cleared