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

RadGrid FilterExpressions HELP!!!!

4 Answers 167 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 29 Sep 2011, 10:28 PM
Ok I've been struggling with this all day and have been all over this site and forums and can't crack this one. I think the issue is I do not know the proper syntax for the regular expression but not sure. It is a bool field that is populating a GridBoundColumn. The text that appears in the results is "True" or "False"

So the use case is to auto default my grid to show only records where the Active field equals true. The grid was populating successfully everything was working beautifully up until I tired to add the default filter.

(some irrelevant code has been removed for privacy)

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
       AllowPaging="True" CellSpacing="0" GridLines="None" PageSize="25" Skin="Windows7"
       Width="100%" AutoGenerateColumns="False" OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated"
       OnItemCommand="RadGrid1_ItemCommand" OnNeedDataSource="RadGrid1_NeedDataSource"
       OnInit="RadGrid1_Init" OnInsertCommand="RadGrid1_ItemCommand">
       <ExportSettings ExportOnlyData="True" OpenInNewWindow="True" FileName="DataExport"
           IgnorePaging="True" Excel-FileExtension="xls" Excel-Format="ExcelML">
           <Excel Format="ExcelML"></Excel>
       </ExportSettings>
       <MasterTableView IsFilterItemExpanded="True" CommandItemDisplay="Top" >
           <CommandItemSettings ShowAddNewRecordButton="true" ShowExportToExcelButton="True"
               ShowExportToCsvButton="True" AddNewRecordText="Add" />
           <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
           </RowIndicatorColumn>
           <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
           </ExpandCollapseColumn>
           <Columns>               
               <telerik:GridBoundColumn DataField="Active" FilterControlAltText="Filter Active column"
                   HeaderText="Active" FilterControlWidth="65%" UniqueName="Active" DataType="System.Boolean">
               </telerik:GridBoundColumn>                
           </Columns>
           <EditFormSettings>
               <EditColumn FilterControlAltText="Filter EditCommandColumn column">
               </EditColumn>
           </EditFormSettings>
       </MasterTableView>
       <FilterMenu EnableImageSprites="False">
       </FilterMenu>
       <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
       </HeaderContextMenu>
   </telerik:RadGrid>

Code behind

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = MyInfo.Get();
  
  
            if (!Page.IsPostBack)
            {
                RadGrid1.MasterTableView.FilterExpression = "(Active = true)";
  
                GridColumn col = RadGrid1.MasterTableView.GetColumnSafe("Active");
                col.CurrentFilterFunction = GridKnownFunction.EqualTo;
                col.CurrentFilterValue = "true";
            }
        }

error message

Server Error in '/' Application.

No property or field 'Active' exists in type 'DataRowView'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Telerik.Web.UI.ParseException: No property or field 'Active' exists in type 'DataRowView'



Additional syntax that has been tried but was also unsuccessful

[Active] = 'true'
[Active] = 'True'
Active = 'true'
Active = True
[Active] EqualTo 'true'
[Active] EqualTo 'True'
[Active] EqualTo true
[Active] EqualTo True

Any help would be great!

~Mike


4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 30 Sep 2011, 06:43 AM
Hi Mike,

You can try by setting "EnableLinqExpressions" of the RadGrid component  to false.

Thanks,
Princy.
0
Mike
Top achievements
Rank 1
answered on 30 Sep 2011, 04:29 PM
Thank you that worked instantly. Can you explain to me why this worked?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Oct 2011, 09:33 AM
Hello,

http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

When the LINQ expressions of the RadGrid are enabled, the performance is significantly improved because the grid uses dynamic LINQ expressions for all data operations.
However, this leads to some limitations and that is why the EnableLinqExpressions property is provided.



Thanks,
Jayesh Goyani
0
Sudharshan
Top achievements
Rank 1
answered on 20 Mar 2014, 04:22 AM
Some of the limitations. I have found is that "Number of items in Pages" for example "28 items in 1", count isn't changing when we use filter for any of the column in RadGrid.

I have removed "EnableLinqExpressions" from RadGrid. I have implemented below code snippet.
NOTE: If you are binding RadGrid with Dataset,  this approach works fine..

DataRow[] drActive = dsActive.Tables(0).Select("Active =True'");
if (drActive.Length > 0) {
DataTable dtActive = drActive.CopyToDataTable();
RadGrid1.DataSource = dtActive;
GridColumn gridColumn = RadGrid1.MasterTableView.GetColumnSafe("Active");
gridColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
gridColumn.CurrentFilterValue = "true";
RadGrid1.Rebind();
}
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Sudharshan
Top achievements
Rank 1
Share this question
or