Hi,
I have upgraded my telerik version from 2014.2.618.45 to 2015.3.1111.45.
In Previous version i was not facing any date format issue, but in new version if i drop any field of type DateTime to Row/Column Field the date show only Year as value.
I have tried to correct this by using below in RadPivotGrid1_PreRender(object sender, EventArgs e) :
RadPivotGrid1.Fields[i].DataFormatString = "{0:dd.MM.yyyy}";
but it changed the data cell value , not the column,row field value.
PFA image for reference.
8 Answers, 1 is accepted
It looks like Fields[i] is happened to be the AggregateField, and this is the reason format applies to the aggregates rather than the column headers.
You may want to set the DataFormatString inside the markup declaration of your "Task Last Modified Date" PivotGridColumnField.
If you continue to have the problem, please share with us the markup of your PivotGrid.
Regards,
Vasil
Telerik
Hi Vasil
Below is my Pre_Render function code :
for (int i = 0; i < RadPivotGrid1.Fields.Count; i++)
{
string fieldName = RadPivotGrid1.Fields[i].DataField;
if (this.SystemFieldList != null)
{
SystemFieldView systemFieldList = this.SystemFieldList.FirstOrDefault(q => q.SystemFieldName.Equals(fieldName, StringComparison.OrdinalIgnoreCase));
if (systemFieldList != null)
{
string SystemFieldLabelSearch = systemFieldList.SystemFieldXMLLabelSearch;
if (!String.IsNullOrEmpty(SystemFieldLabelSearch))
{
RadPivotGrid1.Fields[i].Caption = SystemFieldLabelSearch;
}
//To remove time from datetime
foreach (var dateField in this.systemFieldList.Where(q => q.SystemFieldTypeId == 3).Select(q => new { q.SystemFieldName, q.IsTimeDisplayed }).ToArray())
{
RadPivotGrid1.Fields[i].DataFormatString = "{0:dd.MM.yyyy}";
}
}
}
}
And I cannot add in markup as these columnare dynamic not static. Attached is my markup code.
If you add the fields dynamically, I would suggest you to set the DataFormatString during the FieldCreated event, to be sure it is applied in the correct time of the page lifecycle.
protected
void
PivotGrid1_FieldCreated(
object
sender, PivotGridFieldCreatedEventArgs e)
{
e.Field.DataFormatString =
"{0:dd.MM.yyyy}"
;
}
Regards,
Vasil
Telerik
Hi Vasil,
I have added the below code to all three ( RadPivotGrid1_AddingFieldToZone, RadPivotGrid1_FieldCreated and PreRender) functions :
foreach (var dateField in this.SystemFieldList.Where(q => q.SystemFieldTypeId == 3).Select(q => new { q.SystemFieldName, q.IsTimeDisplayed }).ToArray())
{
if (e.Field.DataField == dateField.SystemFieldName)
{
e.Field.DataFormatString = "{0:dd.MM.yyyy}";
}
}
but its not reflecting the correct date format still showing the year only, though at runtime if i debug,the DataFormat as we specify in above code. Attached is the screenshot.
Also if i Just tried the static statement for the same it worked (quite surprising), adding screenshot of markup for reference.
Could you please let me know how you add the fields to the PivotGrid on the server. Since you have add the PivotGrid declarative you need to add the fields on Page_Load event handler as demonstrated in the following live example. Also could you please try setting the DataFormat string when you create the filed and check whether this will work in your case?
Regards,
Kostadin
Telerik
Hi Kostadin
I bind the datasource in NeedDataSource (which bind the columns selected by user in All Fields section). I don't add the fields in any particular event/function. As per the columns dragged by user in different fields,we save the Pivot settings using RadPersistanceManager.
As i mentioned earlier I've tried to set the DataFormatString (depending on the datatype of column) in three methods( RadPivotGrid1_AddingFieldToZone, RadPivotGrid1_FieldCreated and PreRender) but its not working for me.
Also just for information: I've integrated chart with PivotGrid and drilldown functionality implemented.
I really need some solution for this. Thanks in advance.
I prepared a small sample where I add a format string on FieldCreated server event and on my side the format is applied properly. Could you please check out the attached sample and let me know how it differs from your real setup? I would appreciate if you can replicate the issue either in my sample or in a small runnable one in order to investigate it further.
Regards,
Kostadin
Telerik