Binding columns to an array

Gentlemen,

is there a possibility to bind the TreeGrid columns to an array, please? I have the following structure:

public class ISDetails

    {

        public string strDate{ get; set; }

        public decimal SumValue { get; set; }

        public decimal PercValue { get; set; }

    }

    public class IncomeStmt

    {

        public string NewAccountNo { get; set; }

        public string Parent { get; set; }

        public decimal Total { get; set; }

        public decimal TotalPerc { get; set; }

        public ISDetails[] ISD { get; set; }

    }

I can not use the AuoGeneration of the columns, because I don't want to show the Parent field. How can I diyplay this structure in the TreeGrid?

Thanks!


3 Replies

PS Pon Selva Jeganathan Syncfusion Team October 15, 2021 11:07 AM UTC

Hi Peter,   
 
Thanks for contacting syncfusion forum. 
 
Query: is there a possibility to bind the TreeGrid columns to an array. I can not use the AuoGeneration of the columns, because I don't want to show the Parent field. How can I diyplay this structure in the TreeGrid? 

Yes, you can dynamically bind the array value into TreeGrid column. Please refer to the below code snippet,

 
<SfTreeGrid ChildMapping="Children" @ref="treegrid" TreeColumnIndex="1" DataSource="@TreeData" TValue="BusinessObject" Columns="@Cols1"> 
    
</SfTreeGrid> 
 
 
@code{ 
    SfTreeGrid<BusinessObject> treegrid; 
    public List<TreeGridColumn> Cols = new List<TreeGridColumn>(); 
    public List<TreeGridColumn> Cols1 = new List<TreeGridColumn>(); 
     
     
protected override void OnInitialized() 
    { 
        …… 
 
         Cols.Add(new TreeGridColumn() { Field = "TaskId", HeaderText = "Task ID", Width = "80" }); 
        Cols.Add(new TreeGridColumn() { Field = "TaskName", HeaderText = "Task Name", Width = "160" }); 
        Cols.Add(new TreeGridColumn() { Field = "Duration", HeaderText = "Duration", Width = "80" }); 
        Cols.Add(new TreeGridColumn() { Field = "Progress", HeaderText = "Progress", Width = "160" }); 
        Cols1 = Cols.ToList(); 
    } 
} 
 
 
 

Please refer to the below sample:

https://www.syncfusion.com/downloads/support/directtrac/169642/ze/BlazorServerApp-1577963517

Please refer to the below help documentation:

https://blazor.syncfusion.com/documentation/treegrid/columns/

Please refer to the below API documentation,

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.TreeGrid.SfTreeGrid-1.html#Syncfusion_Blazor_TreeGrid_SfTreeGrid_1_Columns

 Kindly get back to us for further assistance.

Regards,  
Pon selva   



PE Peter October 27, 2021 08:54 AM UTC

Dear Pon,

thank you for your answer. It seems my question was not precise enough. I meant to bind the TreeGrid to the structure IncomeStmt in my example. As you can see it contains an array: ISDetails[], what causes me problem. I don't know how to bind the TreeGrid dynamically to this structure.

I mean I would need something like this: 

<TreeGridColumn Field="ISD[5].SumValue" HeaderText="1" Width="100" ></TreeGridColumn>

or

Cols.Add(new TreeGridColumn() { Field = "ISD[3].SumValue", HeaderText = "ISD[3].SumValue", Width = "160"});

But clearly none of the above working.

Thanks:

Peter



PS Pon Selva Jeganathan Syncfusion Team October 29, 2021 03:55 AM UTC

Hi Peter,   
 
Thanks for the update. 
 

Query: As you can see it contains an array: ISDetails[], what causes me problem. I don't know how to bind the TreeGrid dynamically to this structure.

Based o your query, we suggest you use the complex binding feature of the treegrid. We already discussed complex binding in our help documentation.

Please refer to the below help documentation,

https://blazor.syncfusion.com/documentation/treegrid/columns#complex-data-binding

After following the above reference, still faced issue please share us the following details.  
 
  1. If possible, simple issue reproducible sample. 
  2. Share the complete tree grid code example. 
  3. Share the details of your product version.
 
The provided information will be helpful to provide you response as early as possible.   
 
Regards,  
Pon selva   


Loader.
Up arrow icon