+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Module created with module builder in RadGrid

Module created with module builder in RadGrid

2 posts, 0 answered
  1. Chris
    Chris avatar
    4 posts
    Registered:
    14 Jan 2014
    09 Feb 2014
    Link to this post
    Hi,

    We have created a module with the module builder. The content is shown in a RadGrid with filter possibilities. It's working almost perfect. The filter function for dates is working, except regular string fields such as Title doesn't manipulate the grid when I try to filter.  So when I fill in something in the 'Title' filter, the grid does nothing and still shows everything.

    The ASCX
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Overzicht.ascx.cs" Inherits="SitefinityWebApp.Custom.List" %>
     
    <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
     
     
    <telerik:RadAjaxPanel runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
        <telerik:RadGrid AutoGenerateColumns="false" ID="rgEvents" OnItemCreated="rgEvents_ItemCreated"
            AllowFilteringByColumn="True" AllowSorting="True"
            ShowFooter="True" AllowPaging="True" runat="server" Skin="Sitefinity">
            <GroupingSettings CaseSensitive="false"></GroupingSettings>
            <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="True" ShowFooter="True" ItemStyle-VerticalAlign="Top" AlternatingItemStyle-VerticalAlign="Top">
                <Columns>
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Titel">
                    </telerik:GridBoundColumn>
     
                    <telerik:GridBoundColumn AllowFiltering="false" CurrentFilterFunction="Contains" FilterControlWidth="80px" DataField="Type" HeaderText="Type">
                    </telerik:GridBoundColumn>
     
                    <telerik:GridDateTimeColumn ShowFilterIcon="false" AutoPostBackOnFilter="true" CurrentFilterFunction="GreaterThanOrEqualTo" EnableTimeIndependentFiltering="true" DataFormatString="{0:d-M-yyyy}" PickerType="DatePicker" FilterControlWidth="120px" DataType="System.DateTime" DataField="StartDatum" HeaderText="Datum"></telerik:GridDateTimeColumn>
                    <%--<telerik:GridDateTimeColumn ShowFilterIcon="false" AutoPostBackOnFilter="true" CurrentFilterFunction="LessThanOrEqualTo" EnableTimeIndependentFiltering="true" DataFormatString="{0:d-M-yyyy}" PickerType="DatePicker" FilterControlWidth="120px" DataType="System.DateTime" DataField="EindDatum" HeaderText="Eind"></telerik:GridDateTimeColumn>--%>
     
                    <telerik:GridBoundColumn ItemStyle-CssClass="Afst" AllowFiltering="false" DataField="Afstanden" HeaderText="Afstanden">
                    </telerik:GridBoundColumn>
     
     
                    <telerik:GridBoundColumn ItemStyle-CssClass="Met" AllowFiltering="false" DataField="Hoogtemeters" HeaderText="Hoogtemeters">
                    </telerik:GridBoundColumn>
     
                    <telerik:GridBoundColumn AllowFiltering="false" DataField="Moei" HeaderText="Moeilijkheid">
                    </telerik:GridBoundColumn>
     
                    <telerik:GridBoundColumn AllowFiltering="false" DataField="Opm" HeaderText="Opmerking">
                    </telerik:GridBoundColumn>
     
                    <telerik:GridHyperLinkColumn AllowFiltering="false" ItemStyle-CssClass="DetailLink" DataTextFormatString="Bekijk {0}"
                        DataNavigateUrlFields="Title" UniqueName="Title" DataNavigateUrlFormatString="/detail/{0}"
                        Text="Link">
                    </telerik:GridHyperLinkColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>

    The ASCX.CS
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Threading;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.Data.Linq.Dynamic;
    using Telerik.Sitefinity.DynamicModules.Model;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Lifecycle;
    using Telerik.Web.UI;
     
    namespace SitefinityWebApp.Custom
    {
        public partial class List : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-NL");
                Page.MaintainScrollPositionOnPostBack = true;
     
                var providerName = String.Empty;
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
                dynamicModuleManager.Provider.SuppressSecurityChecks = true;
                Type TType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.CLists.CList");
     
                var myCollection = dynamicModuleManager.GetDataItems(TType).OrderBy(d => d.GetValue<DateTime?>("Datum")).Where(pData => pData.Status == ContentLifecycleStatus.Live && pData.GetValue<DateTime?>("Datum") >= DateTime.Now);
     
                rgEvents.DataSource = myCollection;
                rgEvents.DataBind();
            }
     
            protected void rgEvents_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
            {
     
                if (e.Item is GridFilteringItem)
                {
                    RadDateInput picker = ((GridFilteringItem)e.Item)["Datum"].Controls[1] as RadDateInput;
     
                    if (picker != null)
                    {
                        picker.DisplayDateFormat = "dd-MM-yyyy";
                        picker.DateFormat = "dd-MM-yyyy";
                    }
                }
            }
        }
    }

    Do I need to convert custom and normal fields like Title to make filtering possible?
  2. Vassil Vassilev
     Vassil Vassilev avatar
    308 posts
    Registered:
    21 Jan 2015
    12 Feb 2014
    Link to this post
    Hello Chris,

    If you refer to this column:
    <telerik:GridHyperLinkColumn AllowFiltering="false" ItemStyle-CssClass="DetailLink" DataTextFormatString="Bekijk {0}"
                        DataNavigateUrlFields="Title" UniqueName="Title" DataNavigateUrlFormatString="/detail/{0}"
                        Text="Link">
                    </telerik:GridHyperLinkColumn>

    you have set "AllowFiltering" to false. The rest of your code seems fine and there is no obvious reason the filtering not to work.

    Last, I would advise you to use advanced data-binding:
    http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html


    Simple data-binding can be used in simple cases when you do not require the grid to perform complex operations such as
    • Inserting, deleting, and updating records through custom edit forms (WebUserControl or FormTemplate)
    • Grouping
    • Hierarchy relations
    • Filtering 
    • Sorting 
    • Paging

    Regards,
    Vassil Vassilev
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered