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

GridTemplateColumn - missing something simple?

All the examples I could find in your docs or on the forum for GridTemplateColumn use are XAML - trying to figure out what I'm missing in code - likely something silly.
I'm just trying to put two strings on top of one another, pretty basic - action string and a time date string - I use this same DataTemplate for the tooltip template used on a chart output in the same project.  Not seeing what I'm missing here but the page simply doesn't load like this - if I change it to two separate columns it loads fine, just doesn't look like I want.

            SfDataGrid dataGrid = new SfDataGrid();
            dataGrid.ItemsSource = historyList;
            dataGrid.AutoGenerateColumns = false;

            DataTemplate template = new DataTemplate(() =>
             {
                 StackLayout stack = new StackLayout() { Orientation = StackOrientation.Vertical };

                 Label date = new Label();
                 date.SetBinding(Label.TextProperty, "DisplayTime");

                 Label eventAction = new Label();
                 eventAction.SetBinding(Label.TextProperty, "ActionDescription");

                 stack.Children.Add(date);
                 stack.Children.Add(eventAction);
                 return stack;
             });

            GridTemplateColumn oCustomColumn = new GridTemplateColumn
            {
                CellTemplate =template,
                HeaderText = "Action",
            };

            dataGrid.Columns.Add(oCustomColumn);
            dataGrid.ColumnSizer = ColumnSizer.LastColumnFill;
            Content = dataGrid;

6 Replies

SL Sathya Lakshmanan Syncfusion Team June 14, 2016 01:47 PM UTC

Hi Jeff Lindborg,

We have checked your query and you have missed to set the MappingName of the GridTemplateColumn which is why the data has not loaded in the template column.

Refer the below code example in which we have modified your code to get this working.
 
 
SfDataGrid dataGrid = new SfDataGrid(); 
dataGrid.ItemsSource = historyList; 
dataGrid.AutoGenerateColumns = false; 
 
DataTemplate template = new DataTemplate(() => 
{ 
    StackLayout stack = new StackLayout() { Orientation = StackOrientation.Vertical }; 
 
    Label date = new Label(); 
    date.SetBinding(Label.TextProperty, "DisplayTime"); 
 
    Label eventAction = new Label(); 
    eventAction.SetBinding(Label.TextProperty, "ActionDescription"); 
 
   stack.Children.Add(date); 
    stack.Children.Add(eventAction); 
    return stack; 
}); 
 
GridTemplateColumn oCustomColumn = new GridTemplateColumn 
{ 
CellTemplate =template, 
MappingName=" ActionDescription ", 
HeaderText = "Action", 
}; 
 
dataGrid.Columns.Add(oCustomColumn); 
dataGrid.ColumnSizer = ColumnSizer.LastColumnFill; 
Content = dataGrid; 
 
 

Regards,
Sathya 
 



JL Jeff Lindborg June 14, 2016 04:14 PM UTC

cool - I figured it was something basic I overlooked.

It works perfect on iOS, UWP doesn't like the custom column so for that platform I have it stubbed out, however on Android the grid view page doesn't even load.  No error thrown and nothing shows up in the debug output I can spot - not sure what's going on there.  The charts all work ok on Android so something must be wired up wrong for the grid - I'll need to go back and make a new scratch project and see if I can spot what's wrong.

thanks


SL Sathya Lakshmanan Syncfusion Team June 15, 2016 04:54 PM UTC

Hi Jeff Lindborg,

Thanks for your update.

We were unable to reproduce the reported issue on Android , UWP platforms . We have created a sample from your code example and we have attached and output Screenshot deployed on UWP for your reference. Please download the same from the following link.

Sample link: http://www.syncfusion.com/downloads/support/forum/124548/ze/GridTemplateSample1413584027  

In case, if the issue still persists at your side, please do revert us with a modified sample to reproduce the issue with proper replication procedure
to proceed further on this.

Regards,
Sathya 
 
 



JL Jeff Lindborg June 15, 2016 06:46 PM UTC

the UWP project folder in your zip file is empty by the way... the other project types (android, ios, win 8.1, win phone) are ok.



JL Jeff Lindborg June 15, 2016 07:21 PM UTC

well, multiple things here... I think you guys are testing with a newer framework and using local DLLs for the SyncFusion libraries that are different than what I'm getting via NuGet.  

Aside from the empty UWP folder the NuGet packages list each of the projects having version 2.2.0.45 of the Xamarin.Forms library - which I've been told is a no-go when using the current released version of the SyncFusion libraries - so naturally these don't build with the NuGet packages included for SyncFusion locally.  The other sample loaded for me earlier today had the proper 2.1 version referenced, although that project still threw an error when run.

If I set them back to 2.1.0.6529 and also remove the various Android.Support libraries and get everything squared away library wise, it still wont compile (with just the PCL and Android projects in your zip).

so... I think I'm going to just hang tight until the updated version from you guys comes out that supports 2.2 Xamarin Forms and I'll bring my project up to speed and take another run at it - these samples are not complex and your samples simply do not compile and run without issue on either of my development machines (Win 8.1 and Win10 both with VS 2015).  Since your projects are not pulling the SyncFusion libraries from NuGet that leaves me suspicious we're not testing the same versions of these binaries.



HN Harikrishnan N Syncfusion Team June 16, 2016 04:06 PM UTC

Hi Jeff,

Sorry about the inconvenience.

We had tested sample by referring the Syncfusion assemblies through NuGet and we able to the sample running without any problem. We have attached the sample and the output screenshots of the modified sample for your reference which were created to meet your requirements. We have used Xamarin.Forms version 2.1 in this sample.

Sample and Screenshot link: http://www.syncfusion.com/downloads/support/forum/124548/ze/SampleDemoAndScreenshots1456729049 

Regards,
Harikrishnan 


Loader.
Up arrow icon