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

Bind column to model method

I have a model with  a method.

For simplicity, let's say it's List<Person>.

Person has

First
Mid
Last
Full(){
Last + ", " + First + " " + Mid
}

When I try to bind the column:

<GridColumn Field=@nameof(People.Full()) HeaderText="Grower" TextAlign="TextAlign.Left" Width="250"></GridColumn>

it gives an error. 

Then I tried this in the model:

public string FullComputed => Full();

and

<GridColumn Field=@nameof(People.FullComputer) HeaderText="Grower" TextAlign="TextAlign.Left" 
Width="250"></GridColumn>

That just shows as blank.

How can I accomplish this?


1 Reply

SP Sarveswaran Palani Syncfusion Team March 14, 2023 03:41 AM UTC

Hi Keith,

Greetings from Syncfusion support.

We would like to inform you that, we didn’t have direct support to bind values based on your requirement. However, we suggest using our column template feature to customize your column according to your needs. With column templates, you can define your own custom HTML and use it to render the values in the column. This will give you the flexibility to customize the column as per your requirement. We have attached a sample and documentation link for your reference. Let us know if you need any further assistance with this.


<GridColumn HeaderText="Full Name" TextAlign="TextAlign.Center" Width="120">

            <Template>

                @{

                    var employee = (context as EmployeeData);

                    <div> @employee.FirstName  @employee.LastName

                    </div>

                }

            </Template>

        </GridColumn>


Reference: https://blazor.syncfusion.com/documentation/datagrid/column-template

Regards,
Sarvesh


Attachment: SfGridBindValue_f80d4ce9.zip

Loader.
Up arrow icon