We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Call a custom function to transform cell contents

Is there a way to call a custom function on cell content and have it persistent. So when grouping is applied - transformed value is used.

3 Replies

RP Rekha P Syncfusion Team July 13, 2009 04:25 AM UTC

Hi Vasili,

Thank you for your interest in Syncfusion Products.

The GridGroupingControl, when bound to a data source, can be used to perform engine-related operations such as grouping, allowing you to categorize records based on a specific column. The custom grouping can also be enabled on various grid columns and the grouping collections can be maintained. Please refer the Grouping Demo online sample from the link below,

http://samples.syncfusion.com/ASPNET/7.3.0.18/web/Grid.Grouping.Web/samples/3.5/SortingandGrouping/BasicGrouping/cs/groupingbasic.aspx

Have a look at the above sample and let me if this helps you or could you please more specific about your requirement, so that we can look into that and provide you a solution quickly.

Thanks,
Rekha


VS Vasili Sviridov July 20, 2009 08:47 PM UTC

Ok, here's the scenario.

I obtain a DataSet with my report data. The data is in the raw form. For instance the distance is stored in meters per second.

In my report I'd like to format that as either km/h or MPH, depending on the user's preference. I also want to have the text part localized. I could do it all either in Database or in the dataset, prior to getting databound in syncfusion control. But If i do that and have the data as string, then all the grouping and summary capabilities could not be used.

So currently I resort to overriding QueryCellInfo method and using the TableCellIdentity..DisplayTemplate. To override it with my custom ITemplate, containing formatted string. This way I can have the flexibility of summaries on original data, and custom display. However since it's a template - formatted text is not propagated into the Headers for grouped columns. Original double value is displayed there.

Since this way is quite convoluted, I'd like to know whether or not there is an easier way of achieving the same result.

Screenshot attached.

Thanks,
Vasili



Syncfusion_e2d8c2e4.jpg


BM Balaji M Syncfusion Team July 21, 2009 12:27 PM UTC

Hi Vasili,

Thank you for your interest in Syncfuion Products.

Using queryCellStyleInfo event, we can format the reported GroupedHeaderCaption issue.

Please refer the following code snippet,

void GridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Web.UI.WebControls.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
// if the Celltype is RecordFieldCell or AlternateRecordFieldCell then format the record rows
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.Name == "Duration")
{
//Format the Column Duration using formula
e.Style.CellValue = ((Convert.ToInt32(e.Style.CellValue) / (60 * 60))) + "h**" + ((Convert.ToInt32(e.Style.CellValue) / 60) % 60) + "m **" + (Convert.ToInt32(e.Style.CellValue) / (3600 * 60)) + "s";
e.Handled = true;
}

}
else if (e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell)
{
// if Column is grouped then split the GroupCaptionCell
if (this.GridGroupingControl1.TableDescriptor.IsGrouped)
{
string[] groupedCellValues = e.Style.CellValue.ToString().Split('-', ':');
if (groupedCellValues[0].IndexOf("Duration") != -1)
{
//Format the Column Duration using formula
string s1 = (Convert.ToInt32(groupedCellValues[1]) / 3600) + "h **" + ((Convert.ToInt32(groupedCellValues[1]) / 60) % 60) + "m **" + ((Convert.ToInt32(groupedCellValues[1]) / (3600 * 60))) + " s";
e.Style.CellValue = groupedCellValues[0]+ ": " + s1 + "-" +groupedCellValues[2];
}
}
}
}


Please refer the sample from below link.

http://files.syncfusion.com/support/GGC.Web/7.2.0.37/84816/main.htm

The above sample illustrates, the Column "Duration" & GroupCaptionCell are formatted (Custom) using formula in QueryCellInfo event.

Please let me know if this helps you out.

Regards,
M. Balaji



Loader.
Live Chat Icon For mobile
Up arrow icon