How to get the Sort/Filter criteria of rad Grid programatically when a user clicks on pariculr column or filters a column ?

8 posts, 0 answers
  1. Ram
    Ram avatar
    49 posts
    Member since:
    Feb 2009

    Posted 03 Oct 2011 Link to this post

    Hi,

    I am enabling filtering and sorting on my rad Grid and displaying the data.
    here my  requirement is after diaplaying data.. when a uaser clicks on a column/columns to sort I want to fetch that colun name and its data type and its sort order. And in the same way when a user filters a column/columns I want to get that column name and the filtering type value.
    I need all this data for later use in my application ( when a user selects his sort/filter criteria I will save this data and when the same user views tha data again I will load the grid with his default sort/filter criteria, this sort/filter criteria is per user).

    How can I achieve this?

    Thanks,
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Oct 2011 Link to this post

    Hello,

    Get filter detail
    protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
    {
    if (e.CommandName == RadGrid.FilterCommandName)
    {
    string columnname = ((Pair)e.CommandArgument).Second;
    string filtertyype = ((Pair)e.CommandArgument).First;
    }
    }

    get sort detail

    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/sort/defaultcs.aspx


    Let me know if any concern.


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 05 Jan 2013 Link to this post

    Hi Jayesh,
    string columnname = ((Pair)e.CommandArgument).Second;
    What is the 'Pair' ?.


    Thanks & Regards
    Anzar.M
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 05 Jan 2013 Link to this post

    Hello,

    pair is the keyword/class from .net framework (System.Web.UI.pair).

    for more info please check below link.

    http://msdn.microsoft.com/en-in/library/system.web.ui.pair.aspx


    Thanks,
    Jayesh Goyani
  6. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 06 Jan 2013 Link to this post

    Hello Jayesh,
    Its working properly. By similarly, How to get the column unique name while sorting?.

    Thanks & Regards
    Anzar.M
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Jan 2013 Link to this post

    Hi,

    You can get the column UniqueName when the column is sorted as shown below.
    C#:
    protected void RadGrid2_SortCommand(object sender, GridSortCommandEventArgs e)
    {
        string datafield = e.SortExpression;  //access the column Datafield
        foreach (GridColumn col in RadGrid2.MasterTableView.Columns)
        {
            if (col is GridBoundColumn && (col as GridBoundColumn).DataField == e.SortExpression)
            {
                string uniquename = col.UniqueName;  // column uniqueName(of bound column for example)
            }
       }
    }

    Thanks,
    Shinu.
  8. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 07 Jan 2013 Link to this post

    HI Shinu,
    how to get it on item command without using for each loop?.

    Thanks & Regards
    Anzar.M
  9. Anish
    Anish avatar
    4 posts
    Member since:
    Jan 2013

    Posted 07 Jan 2013 Link to this post


    protected void rdgOther_ItemCommand(object sender, GridCommandEventArgs e)
           {
               if (e.CommandName == "Sort")
               {
     
                   string datafield = Convert.ToString(e.CommandArgument);  
                   foreach (GridColumn col in rdgOther.MasterTableView.Columns)
                   {
                       if (col is GridBoundColumn && (col as GridBoundColumn).DataField == Convert.ToString(e.CommandArgument))
                       {
                           string uniquename = col.UniqueName;
     
                       }
                       else if (col is GridTemplateColumn && (col as GridTemplateColumn).DataField == Convert.ToString(e.CommandArgument))
                       {
                           string uniquename = col.UniqueName;
     
                       }
                   }
               }
           }

    This is how to Get in item command with for each loop. please Tell me without For each loop

    Thanks & Regards
    Anish Sethu
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017