Ticket Q263175
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Add new parameters to the client-side SelectionChanged event

ASPxTreeList - How to get NodeKey using the SelectionChanged event on the client side

created 15 years ago

Hi,
I have configured my tree list as follows;
_oTreeList.DataCacheMode = TreeListDataCacheMode.Disabled;
_oTreeList.Settings.GridLines = GridLines.Both;
_oTreeList.Settings.ShowRoot = true;
 _oTreeList.Settings.ShowTreeLines = false;
_oTreeList.SettingsBehavior.AllowFocusedNode = false;
_oTreeList.SettingsBehavior.AllowDragDrop = false;
_oTreeList.SettingsEditing.AllowNodeDragDrop = false;
_oTreeList.SettingsSelection.Enabled = true;
_oTreeList.NodeExpanding += new TreeListNodeCancelEventHandler(NodeExpanding);
_oTreeList.CustomJSProperties += new TreeListCustomJSPropertiesEventHandler(CustomJSProperties);
_oTreeList.ClientSideEvents.NodeClick = "NodeClick";
Javascript:
function NodeClick(s, e) {
    CloseImportOptionsMenu();
    bScroll = true;
    var srcEl = null;
    var bIsShift = false;
    var bIsCtrl = false;
    var sNodeKey = typeof (e.nodeKey) == "undefined" ? s.GetFocusedNodeKey() : e.nodeKey;

if (typeof(e.htmlEvent) != "undefined") {
        srcEl = e.htmlEvent.srcElement ? e.htmlEvent.srcElement : e.htmlEvent.target;
        bIsShift = e.htmlEvent.shiftKey;
        bIsCtrl = e.htmlEvent.ctrlKey;
    }
    if (srcEl != null && srcEl.tagName == 'IMG') {
        var Selected = isCtrl == false || s.IsNodeSelected(sNodeKey) == false;
        s.SelectNode(sNodeKey, Selected);
        SetImportNodeClass(s, sNodeKey);

e.cancel = true;
        return;
    }
    if (bIsShift || bIsCtrl)
        _aspxClearSelection();
    if (bIsShift == false && bIsCtrl == false)
        ClearTreeSelection(s);

if (bIsShift && s.cpLastSelected != null) {
        var row1 = s.GetNodeHtmlElement(s.cpLastSelected);
        var row2 = s.GetNodeHtmlElement(sNodeKey);
        var index1 = row1.rowIndex;
        var index2 = row2.rowIndex;
        if (index1 > index2) {
            var temp = index1;
            index1 = index2;
            index2 = temp;
        }
        var table = row1.parentNode.parentNode;
        for (var n = index1; n <= index2; n++) {
            var key = s.GetNodeKeyByRow(table.rows[n]);
            if (key != null) {
                s.SelectNode(key, true);
                SetImportNodeClass(s, key);
            }
        }
    }
    else {
        var Selected = bIsCtrl == false || s.IsNodeSelected(sNodeKey) == false;
        s.SelectNode(sNodeKey, Selected);
        SetImportNodeClass(s, sNodeKey);
    }
     LastSelectedNodeKey = sNodeKey;
}
When a user selects the node via the checkbox (SettingsSelection.Enabled = true) it doesn't trigger the NodeClcik event so I have added the following; _oTreeList.ClientSideEvents.SelectionChanged = "NodeClick"; but am unable to get the NodeKey of the focused node as I have disabled it.
How can I achieve this?
Cheers

Show previous comments (2)

    Hello Jason,
    Thank you for the detailed description of the issue. The current ASPxTreeList's implementation doesn't provide the functionality to obtain the key of a selected ASPxTreeList's node by handling the ASPxClientTreeList's SelectionChanged. We have the corresponding suggestion regarding this: Add new parameters to the client-side SelectionChanged event. Please track this suggestion to be notified when its status is changed.
    As a possible solution, I suggest that you use the solution based on the How to use ASPxCheckBox in DataItemTemplate to emulate a selection and How to select a row in one click examples.
    Regards,
    Mike

      Found a way of obtaining the last selected nodekey on the SelectionChanged Event;
      function NodeSelect(s, e) {
       var sNodeKeys = s.GetSelectionInput()['value'].split(' ');
       var sNodeKey = sNodeKeys.length > 1 ? sNodeKeys[sNodeKeys.length - 1] : sNodeKeys[0];
       treeLinking.cpLastSelected = sNodeKey;
      }

        Hello Jason,
        We are glad to hear that you have found a solution. However, the GetSelectionInput method is private, so I can't guarantee that it'll work in all situations.
        Thanks,
        Mike

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.