Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
igTree Rebinding CheckBoxes After Invalid Request
posted

I'm looking for some assistance with an issue I'm having with igTree.

I have a three level deep tree that is an organizational hierarchy.

Region -> District -> Store

A certain piece of functionality in an application I am developing requires us to allow a user to create a new event that can be assigned nationally or to multiple nations but to allow for exclusions at each level of the organizational hierachy. This is where the treeview comes into play.

I can properly save this event and the "exclusions" from the tree when the user inputs everything perfectly on the first go. Where I run into problems is when a user misses a validation rule on create or when I am attempting to allow the user to edit the event.

In these scenarios I have to re-bind all of the selections the user has already input as a server roundtrip occurs.

Currently, I'm roundtripping a collection of the hierarchy exclusion information by stringify'ing it and stuffing it into a hidden field like so:

-----------------------

var checkedNodes = $("#tree").igTree("checkedNodes");
 
var selectedExcludeNodes = [];
 
$.each(checkedNodes, function (index, newCheckedNode) {
 
    var excludeNode = {
        Name: newCheckedNode.data.Name,
        Identifier: newCheckedNode.data.Identifier,
        Level: newCheckedNode.data.Level,
        ParentIdentifier: newCheckedNode.data.ParentIdentifier
    };
    selectedExcludeNodes.push(excludeNode);
 
});
 
var jsonExclusionData;
 
try {
    jsonExclusionData = JSON.stringify(selectedExcludeNodes);
} catch (e) {
    alert(e);
    return false;
}
$("#ExcludedObjects").val(jsonExclusionData);

-----------------------

This works great.
The next step on a server error was to re-bind the checked checkboxes

to the grid. I figured I could do something like so:

-----------------------
var excludedObjects = JSON.parse($("#ExcludedObjects").val());
 
$.each(excludedObjects, function (index, excludeNode) {
    var matchedNodes = $("#tree").igTree("nodesByValue", excludeNode.Identifier.toString());
 
    $.each(matchedNodes, function (innerIndex, matchedNode) {
        if (excludeNode.Level === matchedNode.Level) {
            $("#tree").igTree("toggleCheckstate", matchedNode);
            return false; //Break out of each
        }
    });
 
 
});

 

-----------------------

Sadly, "nodesByValue" doesn't seem to actually return a node object that would have a Data collection.
It seems to be just the HTML elements matched. "nodeDataFor" would have been great as well except the only

method I see only takes a path value and not a value to match.

 

Is there a way to achieve what I'm trying to do? I want the Data collection of a given node by specifiying an identifier to match. How can I achieve this goal?

 

Thanks

  • 5105
    Suggested Answer
    Offline posted

    Hi there,

    You can still use the nodesByValue method. This returns jQuery objects, which you can then run through nodeFromElement: function (element)

    nodeFromElement would turn your jQuery object into a node object with the corresponding data, path and bindings. Let me know if this works for you!

    Thank you for using the Infragistics forums!