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

FilterExpression disable Paging

5 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 1
Lukas asked on 14 Jan 2014, 11:19 AM
Hello,

I am using the Filterexpressions to filter a Grid depending of an DropDownList.

Here is the Code from the GridView:
<telerik:RadGrid ID="ContactsGrid" runat="server" AllowAutomaticDeletes="True"
                            AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
                            AllowSorting="True" Culture="de-DE" DataSourceID="contacts"
                            GridLines="None" Height="100%" OnItemCreated="ContactsGrid_ItemCreated"
                            OnItemInserted="ContactsGrid_ItemInserted"
                                OnPreRender="ContactsGrid_PreRender"
                                onneeddatasource="ContactsGrid_NeedDataSource"                                
                                onitemdatabound="ContactsGrid_ItemDataBound">                               
                            <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top"
                                DataKeyNames="ContactsID" DataSourceID="contacts" InsertItemPageIndexAction="ShowItemOnCurrentPage">
                                <Columns>
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton"
                                        UniqueName="EditCommandColumn">
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridBoundColumn DataField="ContactsID" DataType="System.Int32"
                                        FilterControlAltText="Filter ContactsID column" HeaderText="ContactsID"
                                        SortExpression="ContactsID" UniqueName="ContactsID">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="CustomerID" DataType="System.Int32"
                                        FilterControlAltText="Filter CustomerID column" HeaderText="CustomerID"
                                        SortExpression="CustomerID" UniqueName="CustomerID">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Name" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Name column" HeaderText="Name"
                                        SortExpression="Name" UniqueName="Name">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Lastname" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Lastname column" HeaderText="Lastname"
                                        SortExpression="Lastname" UniqueName="Lastname">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Telephone" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Telephone column" HeaderText="Telephone"
                                        SortExpression="Telephone" UniqueName="Telephone">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Mobile" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Mobile column" HeaderText="Mobile"
                                        SortExpression="Mobile" UniqueName="Mobile" AutoPostBackOnFilter="False">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="E_Mail" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter E_Mail column" HeaderText="E_Mail"
                                        SortExpression="E_Mail" UniqueName="E_Mail">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Fax" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Fax column" HeaderText="Fax" SortExpression="Fax"
                                        UniqueName="Fax">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Department" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Department column" HeaderText="Department"
                                        SortExpression="Department" UniqueName="Department">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Notification" DataFormatString="<nobr>{0}</nobr>"
                                        FilterControlAltText="Filter Notification column" HeaderText="Notification"
                                        SortExpression="Notification" UniqueName="Notification">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
                                        Text="Delete" />
                                </Columns>
                                <EditFormSettings>
                                    <EditColumn ButtonType="ImageButton" />
                                </EditFormSettings>
                            </MasterTableView>
                            <ClientSettings>
                                <Selecting AllowRowSelect="True"></Selecting>
                            </ClientSettings>
                        </telerik:RadGrid>

In the SelectedIndexChanged-Event from the DropDownList i have this code:

ContactsGrid.MasterTableView.FilterExpression = "it.CustomerID = " + e.Index;
ContactsGrid.MasterTableView.Rebind();

When i now Change the DropDownList and the Grid is filtered, the paging disappears and i only see the first page wich show 10 records. But there are more than 10 records that match in the filterexpression.

How can i enable the paging again?

Kind regards
Lukas

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2014, 05:56 AM
Hi Lukas,

From your code I see that you have used DataSourceID as well as OnNeedDataSource event. Please use either one of it. Below is how i Filtered the Grid using OnNeedDataSource event on DropDownList, OnSelectedIndexChanged event.

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int val = Convert.ToInt16(DropDownList1.SelectedValue);
    ContactsGrid.MasterTableView.FilterExpression = "([CustomerID] = '"+val+"') ";
    GridColumn column = ContactsGrid.MasterTableView.GetColumnSafe("CustomerID");
    column.CurrentFilterFunction = GridKnownFunction.EqualTo;
    column.CurrentFilterValue = val.ToString(); 
    ContactsGrid.MasterTableView.Rebind();
}

If this doesn't help, please provide your full code behind.

Thanks,
Princy




0
Lukas
Top achievements
Rank 1
answered on 15 Jan 2014, 08:49 AM
Hello Princy,

I have now deleted the OnNeedDataSource-Event from the Grid an tried your Filter-Function. First i want to say that i forgot to tell wich DataSource i use. I use an EntityDataModel for the Grid.

As far as i can see in your documentation. When i use the EntityDataModel i must use the following Filterexpression:

ContactsGrid.MasterTableView.FilterExpression = "it.CustomerID = " + e.Index;
GridColumn column = ContactsGrid.MasterTableView.GetColumnSafe("CustomerID");
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = e.Index.ToString();
ContactsGrid.MasterTableView.Rebind();

Am i right? Or did i miss something?

I have Attached some Screenshots. First you can see the unfiltered RadGrid where the paging is active.
In the second Screenshot i filtered the RadGrid with the code i write a few lines before. The Filter is set to :
ContactsGrid.MasterTableView.FilterExpression = "it.CustomerID = 4";

There you can see that the paging is disabled.
In the third screeshot i sorted the Grid so that you can see that there are more Records to show but the paging is not showing.

The code for the RadGrid is the same as in my first post except the OnNeedDataSource-Event wich i deleted, the event was empty anyway. Filtering is the same as the code provided in this post.

This is the EntityDataSource:
<asp:EntityDataSource ID="contacts" runat="server"
  ConnectionString="name=Customer_contacts"
  DefaultContainerName="Customer_contacts"
  EntitySetName="Customer_Contacts" EnableDelete="True" EnableInsert="True"
  EnableUpdate="True">
</asp:EntityDataSource>

I hope this will help to solve my issue with your help.

Thanks!

Kind regards
Lukas



0
Princy
Top achievements
Rank 2
answered on 16 Jan 2014, 05:44 AM
Hi Lukas,

I was not able to replicate the issue here is the full code snippet that i tried to filter using EntityDataSource, can you please check it with your code and find out the differences.

ASPX:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" DataTextField="ShipVia"
    DataSourceID="EntityDataSource2" DataValueField="ShipVia" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="EntityDataSource1"
    AllowPaging="true" AllowFilteringByColumn="true" AllowSorting="true" EnableLinqExpressions="false">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID"/>         
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            <telerik:GridBoundColumn DataField="ShipVia" HeaderText="ShipVia" UniqueName="ShipVia" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=Northwind_newEntities"
    DefaultContainerName="Northwind_newEntities" EnableFlattening="False" EntitySetName="Orders"
    OrderBy="it.OrderID DESC" Select="it.[OrderID], it.[ShipVia], it.[ShipCity]"
    EntityTypeFilter="Order">
</asp:EntityDataSource>
<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=Northwind_newEntities"
    DefaultContainerName="Northwind_newEntities" EnableFlattening="False" EntitySetName="Orders"
    EntityTypeFilter="Order" Select=" Distinct it.[ShipVia]">
</asp:EntityDataSource>

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int value = Convert.ToInt16(DropDownList1.SelectedValue);
    RadGrid1.MasterTableView.FilterExpression = "it.ShipVia = " + value;
    GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("ShipVia");
    column.CurrentFilterFunction = GridKnownFunction.EqualTo;
    column.CurrentFilterValue = value.ToString();
    RadGrid1.MasterTableView.Rebind();
}

Thanks,
Princy
0
Lukas
Top achievements
Rank 1
answered on 16 Jan 2014, 12:40 PM
Hello Princy,

Thanks for your help!

I have located the Error. The "AllowFilteringByColumn" was set so "false". I think this is the reason that the paging was disabled after the filtering. I haven´t know that i can only use the FilterExpression when i set this value to true.

So for now, i will disable paging at my Website because i don´t want that the user set the filter manually in the Grid. It should be only allowed via the DropDownList.

It´s not a high priority but is filtering via FilterExpressions possible when i have disabled FilteringByColumn and paging set to true?

Kind regards

Lukas
0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Jan 2014, 04:15 AM
Hi Lukas,

For the FilterExpression to work you need to set the AllowFilteringByColumn property to true. In case if you want to hide the filter row but perform filter you can try the following approach. On the DropDownList's SelectedIndexChanged event, enable the filtering but hide the filter row so that the filter will be done through DropDownList's selection.

ASPX:
<telerik:RadGrid CssClass="HiddenFilter" . . >

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
  RadGrid1.MasterTableView.AllowFilteringByColumn = true;// Enable Filtering
  int value = Convert.ToInt16(DropDownList1.SelectedValue);
  RadGrid1.MasterTableView.FilterExpression = "it.CustomerID= " + value; 
  RadGrid1.MasterTableView.Rebind();
}

CSS:
<style type="text/css">
  .HiddenFilter .rgFilterRow
    {
      display: none;
    }
</style>

Thanks,
Princy


Tags
Grid
Asked by
Lukas
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lukas
Top achievements
Rank 1
Share this question
or