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

How to Implement Filtering Operation on Grid

12 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranganath
Top achievements
Rank 1
Ranganath asked on 12 Jun 2008, 12:45 PM

Hi,

I am trying to Implement Sorting & Filtering properties on Gird . I am able to do Sorting but not Filtering.

For this I wrote the code as follows

 

.aspx:-

<div>

        <asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager>

        <!-- content start -->

        <telerik:RadAjaxManager ID="RadAjaxManager2" DefaultLoadingPanelID="RadAjaxLoadingPanel1"

            runat="server">

            <AjaxSettings>

                <telerik:AjaxSetting AjaxControlID="RadGrid1">

                    <UpdatedControls>

                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

                    </UpdatedControls>

                </telerik:AjaxSetting>

            </AjaxSettings>

        </telerik:RadAjaxManager>

        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px"

            Width="75px" Transparency="5">

            <img style="margin-top: 150px;" alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading4.gif") %>' />

        </telerik:RadAjaxLoadingPanel>

        <telerik:RadGrid ID="RadGrid1" ShowGroupPanel="True" AllowFilteringByColumn="True"

            Skin="Mac" runat="server" AllowPaging="True" AllowCustomPaging="True" PageSize="5"

            VirtualItemCount="100" ForeColor="White" OnGroupsChanging="RadGrid1_GroupsChanging"

            OnNeedDataSource="RadGrid1_NeedDataSource" AllowSorting="True" GridLines="None">

            <%--<MasterTableView VirtualItemCount="25" />--%>

            <FooterStyle ForeColor="#FF3300" />

            <PagerStyle Mode="Slider"></PagerStyle>

        </telerik:RadGrid>

    </div>

 

Aspx.cs:-

protected void Page_Load(object sender, EventArgs e)

    {

        SqlConnection con = new SqlConnection("server=.;database=Pubs;trusted_connection=true");

        SqlDataAdapter dap = new SqlDataAdapter("select * from authors", con);

        DataSet ds = new DataSet();

        dap.Fill(ds, "authors");

        this.RadGrid1.DataSource = ds.Tables[0];

        this.RadGrid1.DataBind();

       

    }

    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

    {

        MyBusinessObjectCollection MyBusinessObjectCollection1 = new MyBusinessObjectCollection();

        int startRowIndex = (ShouldApplySortFilterOrGroup()) ? 0 : RadGrid1.CurrentPageIndex * RadGrid1.PageSize;

 

        int maximumRows = (ShouldApplySortFilterOrGroup()) ?

            MyBusinessObjectCollection1.SelectCount() : RadGrid1.PageSize;

 

        RadGrid1.AllowCustomPaging = !ShouldApplySortFilterOrGroup();

 

        RadGrid1.DataSource = MyBusinessObjectCollection1.Select(startRowIndex, maximumRows);

 

    }

    bool isGrouping = false;

    public bool ShouldApplySortFilterOrGroup()

    {

        return RadGrid1.MasterTableView.FilterExpression != "" ||

            (RadGrid1.MasterTableView.GroupByExpressions.Count > 0 || isGrouping) ||

            RadGrid1.MasterTableView.SortExpressions.Count > 0;

    }

    protected void RadGrid1_GroupsChanging(object source, GridGroupsChangingEventArgs e)

    {

        isGrouping = true;

        if (e.Action == GridGroupsChangingAction.Ungroup && RadGrid1.CurrentPageIndex > 0)

        {

            isGrouping = false;

        }

    }

 

In above manner I tried,but no use.

Any one can guide me with simple steps to implement Filtering operations

 

Thanks,

SRRAO.

12 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Jun 2008, 12:54 PM
Hello Ranganath,

When using NeedDataSource or DataSourceID the grid will handle all automatic operations like paging, filtering, sorting, etc. - you do not need any other code.

You can take for example this dome:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx

and set AllowFilteringByColumn="true".

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ranganath
Top achievements
Rank 1
answered on 12 Jun 2008, 01:08 PM

Hi,

Thanks a lot for your co-operation. But I want to go through with Slider Mode only(<PagerStyle Mode="Slider">)

Please Guide me…!

Thanks,      

Ranganath.S

0
Vlad
Telerik team
answered on 12 Jun 2008, 02:22 PM
Hello Ranganath,

I'm not sure how this is related to the grid filtering - can you clarify?

Regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Princy
Top achievements
Rank 1
answered on 13 Jun 2008, 06:55 AM
Hi,

 You should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding.

Thanks
Princy.
0
t
Top achievements
Rank 1
answered on 07 Jul 2008, 08:13 AM
I got the same problem.
I use the advanced databinding, but filtering doesn't work. Please help me!
0
Sebastian
Telerik team
answered on 07 Jul 2008, 08:16 AM
Hello t,

I tested the demo my colleague Vlad linked in his first reply (enabling the filtering feature of the control) and everything worked as expected on my machine. Can you please test that at your end? Any further details regarding your grid configuration settings can help us determine the cause of the issue to address it accordingly.

Regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
t
Top achievements
Rank 1
answered on 07 Jul 2008, 10:40 AM
Here is my Grid:

<telerik:RadGrid ID="Grid" EnableViewState="true" runat="server" AllowSorting="True" GridLines="None" Skin="Vista" 
                        AllowFilteringByColumn="True" PageSize="30" Pdf-PageHeight="8,5in"   
                        Pdf-PageWidth="11in" AutoGenerateColumns="False" EnableLinqExpressions="False">  
                        <ExportSettings IgnorePaging="True" OpenInNewWindow="True" ExportOnlyData="True" 
                            FileName="ExportData">  
                            <Pdf FontType="Subset" PaperSize="A4" PageWidth="400mm" PageHeight="" /> 
                            <Excel Format="Html" /> 
                            <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> 
                        </ExportSettings> 
                        <MasterTableView CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" 
                            Dir="LTR" Frame="Border" PageSize="20" TableLayout="Auto" 
                            AllowPaging="True">  
                            <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                                Visible="False">  
                                <HeaderStyle Width="20px" /> 
                            </RowIndicatorColumn> 
                            <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                                Resizable="False" Visible="False">  
                                <HeaderStyle Width="20px" /> 
                            </ExpandCollapseColumn> 
                            <EditFormSettings> 
                                <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
                                </EditColumn> 
                            </EditFormSettings> 
                        </MasterTableView> 
                        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowColumnHide="True" 
                            EnableRowHoverStyle="True">  
                            <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" /> 
                        </ClientSettings> 
                    </telerik:RadGrid> 

0
Sebastian
Telerik team
answered on 07 Jul 2008, 10:45 AM
Hello t,

I do not see any binding logic in your post. Can you paste the code-behind of the page to see how you bind the grid instance?

Regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
t
Top achievements
Rank 1
answered on 07 Jul 2008, 11:03 AM
Sorry, I forgot the codebehind:
protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
            {  
                Grid.MasterTableView.AllowPaging = true;  
                Grid.PagerStyle.Mode = Telerik.Web.UI.GridPagerMode.NextPrevAndNumeric;  
                Grid.AllowMultiRowSelection = true;  
                Grid.AllowFilteringByColumn = true;  
                Grid.GridLines = GridLines.Both;  
                Grid.ExportSettings.ExportOnlyData = true;  
                Grid.ExportSettings.OpenInNewWindow = true;  
                Grid.MasterTableView.AllowFilteringByColumn = true;  
                Grid.MasterTableView.Width = new Unit(800, UnitType.Pixel);  
                Grid.ShowStatusBar = true;  
                  
                createGridColumns();  
            }  
           Grid.PreRender += new EventHandler(Grid_PreRender);  
            Grid.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(Grid_NeedDataSource);  
            Grid.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(Grid_ItemCommand);  
            Grid.ItemDataBound += new Telerik.Web.UI.GridItemEventHandler(Grid_ItemDataBound);  
 
        }  
 
 
void Grid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            Grid.MasterTableView.DataSource = objectArray;  
        } 
0
Sebastian
Telerik team
answered on 07 Jul 2008, 11:17 AM
Hello t,

Your implementation seems correct. To progress in our investigation, can you prepare a small working version of your project and send it attached to a support ticket? I will test/debug it on my machine and will get around to you with more info on the matter.

Regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
t
Top achievements
Rank 1
answered on 07 Jul 2008, 01:27 PM
I found out, that the datasource is the problem.

When I use a dataset asa datasource, there is no problem with filtering.

But I have to use this object[] as datasource.

A small project is not so easy to make, because these objects I get from a webservice.
0
t
Top achievements
Rank 1
answered on 08 Jul 2008, 08:29 AM
I found the error.

Grid.MasterTableView.Columns.FindByUniqueName("Selection").Visible = true;  
Grid.MasterTableView.Rebind(); 

When  I delete these 2 lines, everything works
Tags
Grid
Asked by
Ranganath
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Ranganath
Top achievements
Rank 1
Princy
Top achievements
Rank 1
t
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or