adds event handlers to HTML elements of a custom template of Vault items
function listTemplate(item) {
return "<div class='class_name'>" + item.name + "</div>";
}
const vault = new dhx.Vault("vault_container", {
uploader: {
target: "https://docs.dhtmlx.com/vault/backend/upload"
},
downloadURL: "https://docs.dhtmlx.com",
templates: {
list: listTemplate
},
eventHandlers: { onclick: { class_name: function(event) { console.log("You clicked on " + event.target.tagName); // return false; }, }, onmouseover: { class_name: function(event, id) { console.log("Item ID: " + id); }, } } });
vault.data.load("https://snippet.dhtmlx.com/codebase/data/vault/01/dataset.json");
The eventHandlers object includes a set of key:value pairs, where:
Returning false from a handler function will stop the template event bubbling and block triggering of the click event when you click on the item with className.
As an alternative way, you may use stopPropagation()
for this purpose:
eventHandlers: {
onclick: {
class_name: (event) => {
evt = event || window.event;
evt.stopPropagation();
console.log("button click");
}
}
}
added in v5.0
Back to top