RadFileExplorer Grid column sorting

2 posts, 0 answers
  1. Rajeev
    Rajeev avatar
    12 posts
    Member since:
    Jun 2010

    Posted 14 Jul 2011 Link to this post

    Hello All,

    I have a RadFileExplorer in our application which is created dynamically. The grid has two bound columns for which we have to enable column sorting. I have registered the GridSortCommandEventHandler while creating the Grid but the grid is not triggering the Sort event.

    radFileExplorer.Grid.ID = radGridViewName;

    radFileExplorer.Grid.AllowSorting = true;  
    radFileExplorer.Grid.ItemDataBound += new GridItemEventHandler(radFileExplorer_ItemDataBound);  
    radFileExplorer.Grid.SortCommand += new GridSortCommandEventHandler(radFileExplorer_SortCommand);  
    radFileExplorer.TreeView.NodeClick += new RadTreeViewEventHandler(treeView_NodeClick);

    Below is the code written for radFileExplorer_SortCommand event. The below event is not getting invoked on click of the column header.

    void

    radFileExplorer_SortCommand(object sender, GridSortCommandEventArgs e)  

    {

    string sortDir = "ASC";  
    DataView dv = new DataView(Documents);  
    string viewStateKey = "sortDirection" + e.SortExpression;  
    if (ViewState[viewStateKey] != null)  

    {
    sortDir = ((string)ViewState[viewStateKey] == "ASC") ? "DESC" : "ASC";  
    }

    ViewState[viewStateKey] = sortDir;
    dv.Sort = e.SortExpression + 

    " " + sortDir;  
    SortExpression = dv.Sort; 
    GridView docListGrid = (GridView)this.FindControl(radGridViewName);  
    if (docListGrid != null)  
    {

    docListGrid.DataSource = dv;

    docListGrid.DataBind();

    }

    }

    This is quite urgent and any help would be appriciated.

    Many thanks in advance.

    Regards
    Rajeev



  2. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 18 Jul 2011 Link to this post

    Hi Rajeev,

    The grid component of RadFileExplorer is using client-side binding, that is why the SortCommand event is not fired. You can assign handler to the grid's ClientCommand client-side event to apply custom logic during the event, e.g.:
    <telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" OnClientLoad="OnClientLoad">
        <Configuration ViewPaths="~/" />
    </telerik:RadFileExplorer>
     
    <script type="text/javascript">
        function OnClientLoad(oExplorer, args)
        {
            var grid = sender.get_grid();
            grid.add_command(sortCommandHandler);
     
        }
     
        function sortCommandHandler()
        {
            if (args.get_commandName() == "Sort")
            {
                //add custom code here
            }
        }
    </script>

    I hope this helps.

    Regards,
    Dobromir
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top