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

Filtering the grid during load time

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 2
Andy asked on 27 Nov 2012, 10:19 PM
Hi,

I'm having trouble having the grid filtered when it loads. My query lists all users, but I want it to only show users where IsActive = True, which is a checkbox. I used the example here as my template and it seems pretty straightforward. (The last example on the page pertains to checkboxes.)

According to the example, I added
CurrentFilterFunction="EqualTo" CurrentFilterValue="True"
to the checkbox column and it was just fine.

When I add
FilterExpression="([IsActive] = True)"
the grid fails to load and gives me a ParseException error (either "expected expression" with brackets around IsActive, or "No property or field 'IsActive' exists in type 'DataRowView'" without the brackets.

Thanks in advance!

Here is the grid & data source:
<telerik:RadGrid ID="grd_UserAdmin" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" ShowGroupPanel="True"
    Skin="Black" AllowAutomaticInserts="True" ShowFooter="True" DataSourceID="ds_UserAdmin">
    <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True"
        AllowKeyboardNavigation="True" ColumnsReorderMethod="Reorder">
    </ClientSettings>
    <MasterTableView AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" DataKeyNames="UserName"
        EditMode="PopUp" DataSourceID="ds_UserAdmin" FilterExpression="([IsActive] = True)">
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                <ItemStyle CssClass="MyImageButton" />
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn ConfirmText="Delete this user?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                UniqueName="clmDeleteColumn" FilterControlAltText="Filter clmDeleteColumn column">
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="FirstName" FilterControlAltText="Filter FirstName column"
                HeaderText="First Name" SortExpression="FirstName" UniqueName="clmFirstName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="LastName" FilterControlAltText="Filter clmLastName column"
                HeaderText="Last Name" SortExpression="LastName" UniqueName="clmLastName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="UserName" FilterControlAltText="Filter clmUserName column"
                HeaderText="User Name" SortExpression="UserName" UniqueName="clmUserName">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean" FilterControlAltText="Filter clmIsActive column"
                HeaderText="Is Active?" SortExpression="IsActive" UniqueName="clmIsActive" EditFormColumnIndex="1"
                CurrentFilterFunction="EqualTo" CurrentFilterValue="True">
            </telerik:GridCheckBoxColumn>
            <telerik:GridBoundColumn DataField="LastActivityDate" DataType="System.DateTime" FilterControlAltText="Filter clmLastActivityDate column"
                HeaderText="Last Activity Date" SortExpression="LastActivityDate" UniqueName="clmLastActivityDate"
                EditFormColumnIndex="1" ReadOnly="True">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Email" FilterControlAltText="Filter Email column"
                HeaderText="E-Mail" SortExpression="Email" UniqueName="clmEmail" EditFormColumnIndex="1">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>
<telerik:GridDropDownListColumnEditor ID="GridDropDownColumnEditor1" runat="server" DropDownStyle-Width="110px">
</telerik:GridDropDownListColumnEditor>
<asp:SqlDataSource ID="ds_UserAdmin" runat="server" ConnectionString="<%$ ConnectionStrings:Alderman_ConnectionString %>"
    SelectCommand="SELECT * FROM vw_Users"
    DeleteCommand="sp_web_UserAdministration_del" DeleteCommandType="StoredProcedure">
    <DeleteParameters>
        <asp:Parameter Name="UserID" Type="Object" />
    </DeleteParameters>
</asp:SqlDataSource>



2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 28 Nov 2012, 04:21 AM
Hello,

Please try with PreRender event.

protected void RadGrid1_PreRender(object sender, System.EventArgs e)
{
    if (!Page.IsPostBack)
    {
        RadGrid1.MasterTableView.FilterExpression = "([Country] LIKE \'%Germany%\') ";
        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Country");
        column.CurrentFilterFunction = GridKnownFunction.Contains;
        column.CurrentFilterValue = "Germany";
        RadGrid1.MasterTableView.Rebind();
    }
}



Thanks,
Jayesh Goyani
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Nov 2012, 04:42 AM
Hi,

Try setting EnableLinqExpressions as false.
aspx:
<telerik:RadGrid  EnableLinqExpressions="false" ID="RadGrid1" . . .>
</telerik:RadGrid>

Thanks,
Shinu.
Tags
Grid
Asked by
Andy
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or