sna2stha sna2stha - 3 months ago 42x
jQuery Question

Partially select parent node while loading the tree where some childs are checked

I am using jstree checkbox having three states - checked, undetermined and unchecked. When I check the parent node child nodes are auto checked. When I select a child node, parent node is partially selected. I have saved checked, undetermined states as 1 and unchecked as 0 in database.

$('#btnSubmit').bind('click', function (e) {
var checked_ids = [];
$('.jstree-checked, .jstree-undetermined').each(function () {
var id = $(this).children('a').attr('id');

url: '@Url.Action("Action", "Controller")',
type: 'POST',
traditional: true,
data: { AccessIds: checked_ids },
success: function () {
checked_ids.length = 0;
error: function () {
return false;

Now I want to load the tree in three-state. How can I partially select parent if a child is selected.
I am doing something like this:

$(function () {
$('.divchkboxtree #divtree').jstree({
"plugins": ["themes", "html_data", "checkbox", "sort", "ui"]
.bind('loaded.jstree', function () {
$('.Node').each(function () {
var id = $(this).attr('id');
$('.divchkboxtree #divtree').jstree("check_node", '#' + id);

Here '.Node' class holds the checked ids. Now when I load the tree the problem is all nodes are checked where the parent node is checked as I have saved the partially selected value to 1.


Finally I got the answer. I maintained it from the back end. I had a field Object which is null if it is a parent. So what I did was to extract data which are not parent i.e. I extracted those children whose IsSelected is 1 i.e. true and finally the above code worked. No changes on the above code.