Hi,
I have a requirement to control the cascading behavior of checkbox dynamically. In my program the selection and deselection of checkbox happens both by user clicks and programatically. Whenever user clicks on any of the nodes cascading behavior 'Down' is desirable but when the page loads based on some logic I don't want the cascading bahavior, so that already de-selected child nodes doesn't get selected again. But, on load of the page I cannot change the cascading behavior back to 'Down' and as a result of it whenever user again selects some other parent nodes, it's child nodes doesn't get selected automatically.
I am doing this:
<%
String cascadeMode = "Down";
String dataString = ""; //This is the JSON string having parent child relationship established
// and I am setting the value of 'selected' attribute for 'State' property either to true or false dynamically.
if(/*based on some condition*/)
{
cascadeMode = "";
}
%>
<div id="selectiontree" style="padding-right:2px">
</div>
<script>
$( document ).ready( function () {
$.jstree.defaults.core.themes.variant = "small";
var dataS = "";
$( '#selectiontree' ).jstree( {
'plugins': ["checkbox"],
checkbox: {
three_state: false,
cascade: '<%=cascadeMode%>'
},
'core': {
"multiple": true,
"animation": 1,
'data': [
<%=dataString%>,
]
}
} )
.on( 'changed.jstree', function ( e, data ) {
if ( data && data.selected && data.selected.length ) {
//doing something here
}
} )
.on( 'hover_node.jstree', function ( e, data ) {
//doing something here
} )
} );
//Now, on load of the jsp page I want to set the cascading behavior back to "Down" always. It doesn't matter whether current value of "cascadeMode" is "Down" or not.
//Basically I want to do something like this, but this is not working. What is the solution for it?
$( '#selectiontree' ).jstree(true).defaults.checkbox.cascade = "down"; //What is the solution for it?
</script>