Default value
Thank you for this plugin. Very useful! Is it possible to make default selection of some particular element of the tree (on page load)?
From what I've seen while improving this plugin, there is no way to do so. Maybe you could do it yourself within the nodeSource function : when node_id (the first parameter to the nodeSource function) is null, it means this is the initial load. So you could have something like this :
nodeSource: function(node_id, callback) {
// Get your data
// ...
// Call the callback
$cbResult = callback(null, data);
// Select your element (the dirty way)
$myElement.trigger('click');
return $cbResult;
}
(Didn't test this)
Thank you much for reply. But how can I select an element if there is no classes or ids or any properties?
CSS-like selectors are quite powerful, for example, if you want to select the first element (assuming your hColumns has an the id "columns"):
$('#columns').find('ul li:first').trigger('click');
hColumns sets some data-attributes on elements, so if you want to select an element based on the data it represents, you can do it by iterating on the collection:
$('#columns').find('ul li').each(function() {
if ($(this).data('node-data').yourProperty == 'what you are looking for') {
$(this).trigger('click');
}
});
Ooooooh, at last I understood how to do it!!! Your second way works fine! Thank you very much, I spent many hours trying to do it myself. Thanx!
You're welcome, but keep in mind this is just a workaround. There must, or at least may, be a better way to do this.
Sometimes, when some features are not documented, it's worth having a look at the code to understand how it works.
Actually I've done this feature for my own use, I will put this in to our code later :+1:
Any progress on this? I had a request for something similar (when a parent has only one child, they'd like it automatically selected).