An EntityList represents a way building a list or tabular element representation of entities.
The rows of the list are created depending on what type the parent element is. If the parent element is an orderered or unordered list (ol or ul) then the EntityList will create list elements (li) for each element. If the the parent is a table, then the EntityList will create a single table row with a single column (tr > td). For all other cases, the list will generate a div for each entity in the list.
There is also the option to create your own elements for each row for handling more sophisticated lists such as tables with multiple rows, etc.
var display = new thinkmap.display.Display();
thinkmap.entitylist.list(document.getElementById('nodeList'))
.observe(display)
.label(function(entity) {
var data = entity.data;
if (entity.isType('movie')) {
return data.title;
} else if (entity.isType('person')) {
return data.lastname + ', ' + data.firstname;
} else {
return data.genrename;
}
});
thinkmap.entitylist.list(document.getElementById('movieTable'))
.observe(graph)
.condition(function(entity) {
return entity.isType('movie');
})
.createListElement(function(entity) {
var listElement = thinkmap.selection.select(document.createElement('tr'));
var data = entity.data;
listElement.append('td').text(data.title);
listElement.append('td').text(data.year);
listElement.append('td').text(data.rating);
listElement.append('td').text(data.stars);
return listElement.node();
});
thinkmap.entitylist.list(document.getElementById('listDiv'))
.observe(graph)
.condition(function(entity) {
return entity.isType('movie');
})
.label(function(entity) {
return entity.data.title;
})
.on('mouseout', function(entity, rowElement) {
thinkmap.select(rowElement).removeClass('mouseover');
})
.on('mouseover', function(entity, rowElement) {
thinkmap.select(rowElement).addClass('mouseover');
})
.on('click', function(entity, rowElement) {
thinkmap.select(rowElement).toggleClass('selected');
});
Sets (or gets) the comparator used for sorting the list. This comparators follows the same sorting function used for JavaScript arrays where -1 is less than, 0 is equal, and 1 is greater than.
The default value is the natural sorting order of a toString on the entity.
the optional comparator function to set
returns the current comparator function if no arguments were passed or this Entity List if the comparator function was set.
Sets (or gets) the condition for which entities are allowed in the list. The default is any Node.
the optional condition function to set
the condition function if no arguments were passed or this EntityList if the new condition function was set.
Returns true if the entity list contains the given entity
Sets (or gets) the createList element function. This function is responsible for creating each individual row for every entity in the list.
the optional function that builds each row of an entity list and returns the new element. This function is called with the entity, the index of the list this entity will be place, and the parent element of the list. This method should just return a new element and should not append it.
returns the createListElement function if no arguments were passed or this EntityList if a new createListElement function was set.
Returns a selection of list elements within this list.
the optional entity or iterable of entities for which elements to select. If no parameter is passed in, then all the elements are selected.
returns a selection of list elements
Sets (or gets) the labeling function to be used for entities in the entity list. This is the actual text content for the list item. This function will only apply if the default createListElement function has not been changed from the default. If the createListElement function has been overridden, then the label will have no effect as it is called internally by createListElement.
the optional label function to set.
returns the entity label function or this entity list if no arguments were passed.
Marks this entity list to observe a graph. When the entity list observes a graph, it binds listeners to the graph that listen for all entity adds and removes and calls its add and remove methods respectively.
However, this method does not automatically add any existing entities in the graph if the graph is not empty. It will only add and remove from the point in time observe was called. If the graph should also have its exisiting entities be added to the entity list, then the entitylists.add method must be called directly with the given graph as a parameter.
the graph to observe
this entity list
Rebuilds the entity list. This typically should never be called explicitly as it is used more internally to manage what happens when the condition, comparator, createListElement functions are changed on a populated list. This method will cause all of the elements and entities to be removed, causing a removeentity event to be fired, and then readding the elements that were currently in the graph, firing an addentity event for each.
Note, that if a graph was being observed, the graph must explicity be added back into the entity list as that is not done automatically.
whether this refresh should be done immediately or on the next tick of the event loop
returns this entity list
Notifies this entity list to stop observing the given graph.
However, this method does not automatically remove any existing entities in the graph from the list. If the entities from the graph should also be removed from the list, then the entity lists remove method must be called directly with the given graph as a parameter.
the graph to stop observing
this entity list
fired when a row in the list is moused out. The parameter is the entity and the list element
fired when a row in the list is moused over.The parameter is the entity and the list elementt
fired when a row in the list is clicked.The parameter is the entity and the list element
fired when an entity is added to this list. The parameter is the entity added and the element representing it
fired when an entity is removed from this list. The paramter is the entity removed and the element representing it
called when the entity list must rebuild itself. This typically only occurs if the structure of the list is changed at run time such as changing the condition or sorting function of a non-empty entity list