Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am using devexpress controls.

My requirment is I have one treeview

abouve that I want to apply filter for search so I have placed one textbox and on button click it will filter treelist and show those records

but I am not getting results

below is what i have tried so far

ASP.NET
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LocationFilterTreeView.ascx.cs" Inherits="Assistpro.AssistproCRM.WebUI.LocationFilterTreeView" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxTreeList.v15.1, Version=15.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxTreeList" TagPrefix="dx" %>





<dx:ASPxPopupControl ID="pcLocationFilterTreeViewView" runat="server" Modal="True" PopupHorizontalAlign="WindowCenter"
    PopupVerticalAlign="WindowCenter" ClientInstanceName="pcLocationTreeView" HeaderText="Meeting Places" RenderMode="Lightweight"
    AllowDragging="True" EnableAnimation="True" EnableViewState="true" AppearAfter="20"
    ShowCloseButton="True" ShowSizeGrip="False" Width="500px">
    <ContentCollection>
        <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
            <div style="text-align: right">
                <table>
                    <tr>
                        <td>
                            <dx:ASPxTextBox ID="txtLocationFilterTreeViewSearch" ClientInstanceName="txtLocationFilterTreeViewSearch" runat="server" NullText="Search" Width="170px">
                                <ClientSideEvents TextChanged="function(s, e)  { Search(s,e); }" />
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxImage ID="imgLocationFilterTreeViewSearch" runat="server" Height="20px" Cursor="pointer" ImageUrl="~/Images/Report/search.png" ShowLoadingImage="false">
                                <ClientSideEvents Click="function(s, e)  { Search(s,e); }" />
                            </dx:ASPxImage>
                        </td>
                    </tr>
                </table>
            </div>

            <div>
                <table style="width: 100%">
                    <tr>
                        <td>
                            <dx:ASPxTreeList ID="trLocationFilterTreeView" runat="server" DataSourceID="odsLocationFilterTreeView" ClientIDMode="AutoID" Width="100%" OnSelectionChanged="trLocation_SelectionChanged" 
                                SettingsBehavior-AutoExpandAllNodes="true" OnDataBound="trLocation_DataBound" ClientInstanceName="trLocationFilterTreeView"
                                KeyFieldName="LocationID" ParentFieldName="ParentLocationID" EnableCallbacks="false">
                                <Columns>
                                    <dx:TreeListDataColumn FieldName="FullNameWithCode" Caption="Name" Width="100%" />
                                    <dx:TreeListDataColumn FieldName="LocationType" Width="100%" Visible="false" />
                                    <dx:TreeListDataColumn FieldName="LocationID" Width="100%" Visible="false" />
                                </Columns>
                                <Settings ShowColumnHeaders="False" GridLines="None"  SuppressOuterGridLines="false" />
                                <SettingsSelection Enabled="true" />
                                <SettingsPager Mode="ShowPager">
                                    <Summary EmptyText="No data to paginate"></Summary>
                                    <PageSizeItemSettings Items="10, 20, 50" Visible="true" />
                                </SettingsPager>
                                <SettingsBehavior ProcessSelectionChangedOnServer="true" />
                            </dx:ASPxTreeList>
                            <asp:ObjectDataSource ID="odsLocationFilterTreeView" runat="server"
                                SelectMethod="GetLocations"
                                TypeName="Assistpro.AssistproCRM.Presenter.LocationFilterTreeViewPresenter" OnObjectCreating="ods_ObjectCreating"></asp:ObjectDataSource>
                        </td>
                    </tr>
                </table>
                <table>
                    <tr>
                        <td>
                            <dx:ASPxButton ID="btnLocationFilterTreeViewOk" Width="100px" runat="server" Text="Ok" CausesValidation="false" AutoPostBack="false">
                            </dx:ASPxButton>
                            <dx:ASPxCallback ID="cbLocationOkClick" ClientInstanceName="cbLocationOkClick" runat="server"></dx:ASPxCallback>
                        </td>
                        <td>
                            <dx:ASPxButton ID="btnLocationFilterTreeViewCancel" Width="100px" runat="server" Text="Cancel" CausesValidation="false" AutoPostBack="false"></dx:ASPxButton>
                        </td>
                    </tr>
                </table>
            </div>
        </dx:PopupControlContentControl>
    </ContentCollection>
</dx:ASPxPopupControl>




HTML
function Search(s, e) {
    debugger;
    CheckNodeText(trLocationFilterTreeView, s.GetText());
}

function CheckNodeText(current, text) {
    if (text.length > 0)
        for (var i = 0; i < current.GetNodeCount() ; i++) {
            var node = current.GetNode(i);
            var nodeText = node.text;
            var index = nodeText.indexOf(text);
            if (index !== -1) {
                trLocationFilterTreeView.SetSelectedNode(node);
                Expand(node);
                dd.ShowDropDown();
                break;
            }
            CheckNodeText(node, text);
        }
}

function Expand(node) {
    var nodesparent = node.parent;
    while (nodesparent != null) {
        nodesparent.SetExpanded(true);
        nodesparent = nodesparent.parent
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900