Programmatic setting of FilterExpression

6 posts, 0 answers
  1. Oliver
    Oliver avatar
    6 posts
    Member since:
    Jun 2017

    Posted 19 Oct 2017 Link to this post

    Good Day,

    I am trying to implement custom filtering on a Radgrid bound to an SQLDataSource with LINQExpressions disabled, however, I cannot seem to get it working on a particular column.

    Now, the column in question has "Display='False'" as it's a foreign key column pointing to another table. I've then got another column that's binding to another SQLDataSource to get the actual data. As far as I can tell, this is the approved method of joining multiple tables into one RadGrid...

    The problem is that the filterExpression then seems to not be able to see the hidden column. I've also tried filtering on the visible column using both the foreign key and the relevant column from the second table. Neither seems to work. How can I perform filtering on a foreign key column while showing a more pertinent column from the second table?

    Also, I'm storing the selected filter variables in the ViewState. Pertinent code below;

    1.<telerik:GridBoundColumn DataField="fk1_dID" DataType="System.Int32" FilterControlAltText="Filter fk1_dID column" HeaderText="Depot" SortExpression="fk1_dID" UniqueName="fk1_dIDo" Display="False" ReadOnly="true" InsertVisiblityMode="AlwaysHidden">
    2.</telerik:GridBoundColumn>
    3.<telerik:GridDropDownColumn FilterControlAltText="Filter column column" HeaderText="Depot" SortExpression="fk1_dID" UniqueName="fk1_dID" DataField="fk1_dID" DataSourceID="sqlDepot" ListTextField="dCode" ListValueField="dID">
    4.    <FilterTemplate>
    5.        <telerik:RadDropDownList ID="filterDepot" runat="server" DataSourceID="sqlDepot" DataValueField="dID" DataTextField="dCode" OnSelectedIndexChanged="filterDepot_SelectedIndexChanged" AutoPostBack="true" AppendDataBoundItems="true"><Items><telerik:DropDownListItem Value="0" Text="All" /></Items></telerik:RadDropDownList>
    6.    </FilterTemplate>
    7.</telerik:GridDropDownColumn>
    01.private string dateFilter() {
    02.    int y = int.Parse(vsYear);
    03.    int m = int.Parse(vsMonth);
    04.    return ( y != 1990 ? ( m == 0 ? $"([iDate] >= '{y}-01-01' AND [iDate] <= '{y}-12-31')" : $"([iDate] >= '{y}-{string.Format("{0:0#}", m)}-01' AND [iDate] <= '{y}-{string.Format("{0:0#}", m)}-{DateTime.DaysInMonth(y, m)}')" ) : "" );
    05.}
    06.private string depotFilter() {
    07.    return ( vsDepot != "00" ? $"{( vsYear != "1990" ? " AND " : "" )}([fk1_dID] = {vsDepot})" : "" );
    08.}
    09.private string FilterBuilder() {
    10.    dAuth.InnerText = $"{dateFilter()}{depotFilter()}";
    11.    return $"{dateFilter()}{depotFilter()}";
    12.}
    13.protected void filterDepot_SelectedIndexChanged( object sender, DropDownListEventArgs e ) {
    14.    vsDepot = e.Text;
    15.    rglog.MasterTableView.FilterExpression = $"{FilterBuilder()})";
    16.    rglog.MasterTableView.Rebind();
    17.}
  2. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 24 Oct 2017 Link to this post

    Hello Oliver,

    For applying filtering explicitly, you can use the filter method:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/methods/filter

    Here is a live sample:
    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

    Or FireCommandEvent method:
    https://www.telerik.com/forums/radgrid-enable-filter-code-behind#cel1slcp-U-pmV28CfXTrg

    And here is a sample for the Between function:
    https://www.telerik.com/forums/setting-a-filter-in-the-index-changed-event-of-a-drop-down-combo-not-filtering-the-grid#_QnXxSMs5Uq9rddb2JWcWA

    I hope this will prove helpful.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Oliver
    Oliver avatar
    6 posts
    Member since:
    Jun 2017

    Posted 24 Oct 2017 in reply to Eyup Link to this post

    Good Morning Eyup,

    I have already read all the filtering related documentation and dissected the demos. I still can't get it working. Please re-read my post in full and answer my question about filtering columns with "display=false" set, as I believe this is where my issue lies.

    Thanks,

  4. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 27 Oct 2017 Link to this post

    Hello Oliver,

    Modifying the FilterExpression manually is not recommended and you need to let the grid handle its filtering automatically by using the fireCommand or FireCommandEvent methods as demonstrated in the samples provided in my previous reply.

    You can ensure that the field in question is present in the grid datasource and its built-in filtering functions properly without any additional custom logic, for example when the Display property is set to true and the cell values of the column are visible to the user.

    To assist you further for this case, please modify the first sample provided here with a dummy source to reproduce the issue and open a formal support thread to send it back to us for further investigation:
    https://www.telerik.com/forums/how-to-persist-dropdownlist-selected-index-and-value-on-postback-from-radgrid-filtertemplate#GW3MyQLmVEmy8XzsmrHzeQ

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Oliver
    Oliver avatar
    6 posts
    Member since:
    Jun 2017

    Posted 27 Oct 2017 in reply to Eyup Link to this post

    Hi Eyup

    So, just to be clear, I can't filter a column if it's not using the same datasource as the grid, and I can't set the filter from a visible column, to filter the value of a hidden column?

  6. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 31 Oct 2017 Link to this post

    Hello Oliver,

    Let's split these questions in two parts:

    1. "I can't filter a column if it's not using the same datasource as the grid." - I am afraid not.

    2. "I can't set the filter from a visible column, to filter the value of a hidden column." - This is possible.

    You can check the implementation demonstrated in the attached web site sample.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
     
Back to Top