This is a migrated thread and some comments may be shown as answers.

Cancel event in OnItemClick method

3 Answers 25 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 21 Aug 2014, 10:01 AM
how to cancel event in RadTreeList_OnItemClick method.

I am using below code

function RadTreeList_OnItemClick(sender, eventArgs) {

                var currentItem = eventArgs.get_item();
                var item = eventArgs.get_item();                 
                if (item.get_dataKeyValue('IsAlreadyAssigned') == 'True') {
                    if (eventArgs.get_item().get_selected())
                    {
                        <<<I NEED TO CANCEL EVENT HERE , SO IT DOES NOT DO ANYTHING JUST CANCEL IT>>>
                        selItem = '';                        
                    }
                    else
                    {
                        alert('2');                        
                        selItem = item.get_dataKeyValue('ObjectId')
                        eventArgs.get_item().set_selected(true);
                    }
                    
                }
                else {                     
                    selItem = '';                    
                                    
                }

            }

Please help

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 21 Aug 2014, 12:03 PM
Hi Sandeep,

It is very difficult to find out the exact requirement with the provided information. The ItemClick event of RadTreeList is fired when a data item is clicked in the RadTreeList and this event can not be cancelled. Please elaborate your requirement for further help.

Thanks,
Shinu.
0
Sandeep
Top achievements
Rank 1
answered on 21 Aug 2014, 12:18 PM
Hi Shinu,

I am binding data to treelist with few columns, and one column is having value true or false.

I am disabling the row if value is true.

I want user should not be able to select or deselect that row when user click on it.

but it should be selectable or deselectable if user clicks on parentitem row or parent item check box.

Please let me know if I am still not clear.

Regards,
Sandeep
0
Shinu
Top achievements
Rank 1
answered on 22 Aug 2014, 05:36 AM
Hi Sandeep,

Please try the below sample code snippet which works fine at my end.

ASPX:
<telerik:RadTreeList ID="RadTreeList1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID" ParentDataKeyNames="ParentID" AllowMultiItemSelection="True"AutoGenerateColumns="false" ResolvedRenderMode="Classic" OnItemDataBound="RadTreeList1_ItemDataBound">
    <Columns>
        <telerik:TreeListSelectColumn HeaderStyle-Width="38px">
        </telerik:TreeListSelectColumn>
        <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
        </telerik:TreeListBoundColumn>
        <telerik:TreeListBoundColumn DataField="Text" UniqueName="Text" HeaderText="Text">
        </telerik:TreeListBoundColumn>
        <telerik:TreeListBoundColumn DataField="ParentID" UniqueName="ParentID" HeaderText="ParentID">
        </telerik:TreeListBoundColumn>
        <telerik:TreeListCheckBoxColumn DataField="Status" UniqueName="Status" HeaderText="Status">
        </telerik:TreeListCheckBoxColumn>
    </Columns>
    <ClientSettings>
        <ClientEvents OnItemSelected="OnClientNodeClicked" OnItemDeselected="OnClientNodeClicked" />
        <Selecting AllowItemSelection="true" />
    </ClientSettings>
</telerik:RadTreeList>

C#:
protected void RadTreeList1_ItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e)
{
    if (e.Item is TreeListDataItem)
    {
        TreeListDataItem item = (TreeListDataItem)e.Item;
        CheckBox status = item["Status"].Controls[0] as CheckBox;
        if (status.Checked)
        {
            item.Enabled = false;
        }
    }
}

JavaScript:
function OnClientNodeClicked(sender, args) {
    var currNode = args.get_item();
    var childNodes = currNode.get_childItems();
    var nodeCount = currNode.get_childItems().length;
    var parentItem = currNode.get_parentItem();
    if (currNode.get_selected()) {
        CheckAllChildren(childNodes, nodeCount);
    }
    else {
        UnCheckAllChildren(currNode, childNodes, nodeCount);
    }
}
function UnCheckAllChildren(currNode, nodes, nodecount) {
    var i;
    for (i = 0; i < nodecount; i++) {
        nodes[i].set_selected(false);
    }
    currNode.set_selected(false);
}
function CheckAllChildren(nodes, nodecount) {
    var i;
    for (i = 0; i < nodecount; i++) {
        nodes[i].set_selected(true);
    }
}

Thanks,
Shinu.
Tags
TreeList
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Sandeep
Top achievements
Rank 1
Share this question
or