Completed
Last Updated: 26 Jan 2022 10:33 by ADMIN
Release R1 2022 SP1
Sean
Created on: 07 Jan 2022 10:16
Category: GridView
Type: Bug Report
0
RadGridView: Loading layout with a filter for the date column throws error

Use this XML layout: 

 

this.radGridView1.LoadLayout(@"..\..\..\Layout.xml");

 

 

<RadGridView Padding="0, 0, 0, 1" Cursor="Default" TabIndex="49">
<MasterTemplate EnableGrouping = "True" AllowEditRow="False" AllowDeleteRow="False" AllowAddNewRow="False" EnableFiltering="True" AutoExpandGroups="True">
<Columns>
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="JobID" Name="JobID" IsAutoGenerated="True" IsVisible="True" HeaderText="JobID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="CustomerID" Name="CustomerID" IsAutoGenerated="True" IsVisible="True" HeaderText="CustomerID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="285" FieldName="StatusID" Name="StatusID" IsAutoGenerated="True" IsVisible="True" HeaderText="StatusID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="UnitID" Name="UnitID" IsAutoGenerated="True" IsVisible="True" HeaderText="UnitID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="OperatorID" Name="OperatorID" IsAutoGenerated="True" IsVisible="True" HeaderText="OperatorID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="JobTypeID" Name="JobTypeID" IsAutoGenerated="True" IsVisible="True" HeaderText="JobTypeID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="JobCatID" Name="JobCatID" IsAutoGenerated="True" IsVisible="True" HeaderText="JobCatID" />
<Telerik.WinControls.UI.GridViewDateTimeColumn Width="100" FieldName="StartTime" Name="StartTime" IsAutoGenerated="True" IsVisible="True" HeaderText="StartTime">
<FilterDescriptor xsi:type="Telerik.WinControls.Data.DateFilterDescriptor" Value="" IgnoreTimePart="False" PropertyName="StartTime" Operator="IsNotNull" IsFilterEditor="True" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</Telerik.WinControls.UI.GridViewDateTimeColumn>
<Telerik.WinControls.UI.GridViewDateTimeColumn Width="100" FieldName="FinishTime" Name="FinishTime" IsAutoGenerated="True" IsVisible="True" HeaderText="FinishTime" />
<Telerik.WinControls.UI.GridViewDateTimeColumn Width="100" FieldName="CreateDate" Name="CreateDate" SortOrder="Descending" IsAutoGenerated="True" IsVisible="True" HeaderText="CreateDate" />
<Telerik.WinControls.UI.GridViewDateTimeColumn Width="100" FieldName="StatusJobDate" Name="StatusJobDate" IsAutoGenerated="True" IsVisible="True" HeaderText="StatusJobDate" />
<Telerik.WinControls.UI.GridViewTextBoxColumn Width="100" FieldName="UserID" Name="UserID" IsAutoGenerated="True" IsVisible="True" HeaderText="UserID" />
<Telerik.WinControls.UI.GridViewTextBoxColumn DataType="System.Guid" Width="100" FieldName="TableKey" Name="TableKey" IsAutoGenerated="True" IsVisible="False" HeaderText="TableKey" />
</Columns>
<FilterDescriptors>
<Telerik.WinControls.Data.DateFilterDescriptor Value="" IgnoreTimePart="False" PropertyName="StartTime" Operator="IsNotNull" IsFilterEditor="True" />
</FilterDescriptors>
<SortDescriptors>
<Telerik.WinControls.Data.SortDescriptor PropertyName="CreateDate" Direction="Descending" />
</SortDescriptors>
<ViewDefinition xsi:type="Telerik.WinControls.UI.TableViewDefinition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</MasterTemplate>
</RadGridView>

Workaround: 

public class CustomGridView : RadGridView
{
    protected override GridViewLayoutSerializer CreateGridViewLayoutSerializer(Telerik.WinControls.XmlSerialization.ComponentXmlSerializationInfo info)
    {
        return new CustomGridViewLayoutSerializer(info);
    }
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadGridView).FullName;
        }
    }
}

public class CustomGridViewLayoutSerializer : GridViewLayoutSerializer
{ 
    public CustomGridViewLayoutSerializer(ComponentXmlSerializationInfo componentSerializationInfo) : base(componentSerializationInfo)
    {
    }

    protected override bool ProcessReaderAttribute(System.Xml.XmlReader reader, object parentObject, object toRead, PropertyDescriptor property)
    {
        if (toRead is FilterDescriptor && reader.Value == string.Empty)
        {
            object val = reader.Value;
            if (property.ComponentType == typeof(DateFilterDescriptor))
            {
                val = null;
            }
            
            this.SetPropertyValue(property, toRead, val);
            return true;
        }

        return base.ProcessReaderAttribute(reader, parentObject, toRead, property);
    }
}

 

0 comments