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

How to summarize, adding a row in the end and change the column content font color ?

Hi! I'm Raphael, and I'm using sfDataGrid for Xamarin.iOS unified.

I have a datagrid with two columns: "Name" and "Total".

Example:

 -------------   ----------
|    Name     |    Total   |
 -------------   ----------
|  Raphael    |    200,00 |
|  Carlos       |    150,00 |
|  David        |      20,00 |
 -------------   ----------


I need to put an "extra row" with the total value

Something like


 -------------   -----------
|    Name     |    Total    |
 -------------   -----------
|  Raphael    |    200,00  |
|  Carlos       |    150,00  |
|  David        |      20,00  |
|  TOTAL     |     (SUM) |
 -------------   -----------

And this "total row", just for the "total column" (not the "name column) I need to change the font color for green (or red in case of negative values) in execution time.

How can I do this two things ?

Can you help me?

Thanks




1 Reply

HN Harikrishnan N Syncfusion Team September 25, 2015 09:59 AM UTC

Hi Raphael,

Thank you for using Syncfusion Products.

In SfDataGrid, you can change the font color of the text inside the GridCell in execution time by customizing the GridCell. You can add views inside the GridCell and customize the text color in the LayoutSubViews from the sample based on your requirement. Please refer the below code example to know about “how to customize a GridCell”.



GridTextColumn customColumn = new GridTextColumn();

customColumn.UserCellType = typeof(CustomCell);

customColumn.MappingName = "CustomColumn";
SfGrid.Columns.Add(customColumn);

public class CustomCell : GridCell

{

            UILabel stocktext;


            public CustomCell ()

            {

                        stocktext = new UILabel ();

                        stocktext.Font = UIFont.SystemFontOfSize (20);

                        this.Add (stocktext);

                        this.CanRenderUnLoad = false;

            }


            protected override void UnLoad ()

            {

                        this.RemoveFromSuperview ();

            }


            public override void LayoutSubviews ()

            {

                        base.LayoutSubviews ();


                        if (Convert.ToDouble (DataColumn.CellValue) < 0) {

            this.stocktext.TextColor = UIColor.Red;

                        } else {

            this.stocktext.TextColor = UIColor.Green;

                        }

                        this.stocktext.Frame = new CoreGraphics.CGRect (Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);

       this.stocktext.Font = DataColumn.GridColumn.RecordFont;

        this.stocktext.TextAlignment = UITextAlignment.Right;

                        this.stocktext.Text = DataColumn.CellValue.ToString ();

            }


            protected override void Dispose (bool disposing)

            {

                        if (stocktext != null) {

                                    stocktext.Dispose ();

                                    stocktext = null;

                        }

                        base.Dispose (disposing);

            }
}


For more details about customizing the GridCell in SfDataGrid, please refer the Formatting sample and RenderingDynamicData sample in our Demo samples.

Regarding your query to put an extra row to display the summary information in SfDataGrid:
Currently there is no support for this, however we have already considered this as a feature. A support incident to track the status of this feature has been created under your account. Please log on to our support website to check the further updates.

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents 

Please let us know if this helps.

Regards,
Harikrishnan

Loader.
Live Chat Icon For mobile
Up arrow icon