Having two GridColumns based on the same property with different GridColumn.Field

Hey guys, I have a question.
I want to display the same property (BirthDay) in 2 different GridColumns with different formats in my Grid. For some further operations i really need different field names! We use Grid.GetColumnByField at some points, so we can not have the same field names. 

like:

<GridColumn Field=@nameof(OverviewData.BirthDay) HeaderText="BirthDate" TextAlign="TextAlign.Right" @ref=RefToColumn Width="160"></GridColumn>
<GridColumn Field=@(nameof(OverviewData.BirthDay) + ".Date") Format="date" HeaderText="BirthDate.Date" TextAlign="TextAlign.Right" @ref=RefToColumn Width="160"></GridColumn>


That's why I was thinking about complex binding, but i am not sure if this is how it works and if it even works with DateTime? properties.

I've added a testproject, the grid can be found in "SfGridTest.razor". Can you help me find a solution for this?

Best regards

Patrick


Attachment: SfGridTest_8531211d.zip

2 Replies

UN Unknown August 4, 2021 11:54 AM UTC

Format="date" and Format="date-time" works fine.
This is what I want, one column with "01.01.2021 15:16" and another with just "01.01.2021". 

But I NEED them to have different Field values!
As I said we use GetColumnByField at some points to apply custom filtering, grouping and ordering for example. And if two fields have the same Field value I don't know which one I am acutally displaying. Sure the filtered value is the same, but the columns have different HeaderTexts and i display the HeaderText so the people know what they are grouping/filtering and stuff. 

That's why i tried complex binding, just to have different Field values for the columns. But I don't know if this works or maybe you have another solution for this. I need a persistent and unique identifier for the columns.


Sorry for the misscommunication and the weird case.



RS Renjith Singh Rajendran Syncfusion Team August 4, 2021 11:56 AM UTC

Hi Patrick, 

Greetings from Syncfusion support. 

We could see that you would like to display only Date value for the second BirthDay column. If so, then we suggest you to set proper Format property values to achieve this requirement. Please refer and use as like the below highlighted code, 

 
@*Displays only day value of BirthDay*@ 
<GridColumn Field=@nameof(OverviewData.BirthDay) HeaderText="BirthDate" Format="dd" ...></GridColumn> 
@*Displays BirthDay as date and month*@ 
<GridColumn Field=@(nameof(OverviewData.BirthDay)) Format="MMMM dd" ...></GridColumn> 


Reference :  

You can apply custom format to Date Columns by providing your needed format using the Format property of GridColumn based on C# date format as like in above above general link. 

 
Query 2 : For some further operations i really need different field names! We use Grid.GetColumnByField at some points, 
GridColumns can be rendered only based on the Field names from the corresponding Grid model(OverviewData). You cannot define a complex typed Field as GridColumn, if it is not available in And, we are not clear about the exact operations in which you will be facing difficulties when having same Field names. If you are having two same Fields(two BirthDay columns) in grid then you could differentiate same Field columns using different unique HeaderText property value. 
 
If we have misunderstood your requirement or if you are facing any other difficulties, then kindly get back to us with the following details for better assistance. 

  1. Share a detailed explanation of your complete requirement.
  2. Share the case/scenario in which you are facing difficulties when having same Field names.
  3. Share a video demo explaining your requirement.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith R 


Loader.
Up arrow icon