@ -28,7 +28,8 @@
< / head >
< / head >
< body >
< body >
< p >
< p >
This example demonstrates editable groups (for now only reordering).
This example demonstrates editable groups (reordering and hiding).
< button onclick = "showAllGroups()" > Restore Hidden< / button >
< / p >
< / p >
< div id = "visualization" > < / div >
< div id = "visualization" > < / div >
@ -55,7 +56,14 @@
{"content": "WEC", "id": "WEC", "value": 18, className:'endurance'},
{"content": "WEC", "id": "WEC", "value": 18, className:'endurance'},
{"content": "GP2", "id": "GP2", "value": 19, className:'openwheel'}
{"content": "GP2", "id": "GP2", "value": 19, className:'openwheel'}
]);
]);
// function to make all groups visible again
function showAllGroups(){
groups.forEach(function(group){
groups.update({id: group.id, visible: true});
})
};
// create a dataset with items
// create a dataset with items
// note that months are zero-based in the JavaScript Date object, so month 3 is April
// note that months are zero-based in the JavaScript Date object, so month 3 is April
var items = new vis.DataSet([
var items = new vis.DataSet([
@ -299,6 +307,20 @@
a.value = b.value;
a.value = b.value;
b.value = v;
b.value = v;
},
},
groupTemplate: function(group){
var container = document.createElement('div');
var label = document.createElement('span');
label.innerHTML = group.content + ' ';
container.insertAdjacentElement('afterBegin',label);
var hide = document.createElement('button');
hide.innerHTML = 'hide';
hide.style.fontSize = 'small';
hide.addEventListener('click',function(){
groups.update({id: group.id, visible: false});
});
container.insertAdjacentElement('beforeEnd',hide);
return container;
},
orientation: 'both',
orientation: 'both',
editable: true,
editable: true,
groupEditable: true,
groupEditable: true,