Add grid column programatically

I would like to know that if possible I can set the grid column programatically , like adding new column and setting the grid column like this :

List<GridColumn> col = new List<GridColumn>();

private void LoadSettingValue()

{

                       col.Add(new GridColumn() { Field = data[0].ts_field_name,

                               HeaderText = data[0]. ts_label,

                               TextAlign = TextAlign.Left,

                               EditType = EditType.DropDownEdit,

                               EditorSettings = CustomIDEditParams

}

or it can be like this ?

private void LoadSettingValue()

{

               Syncfusion.Blazor.Grids.GridColumn newCol = new GridColumn();

                newCol.Field = data[0] .ts_field_name;

                newCol.HeaderText = data[0] .ts_label;

                if ( data[0] .ts_control_type == "TextBox")

                {

                    newCol.EditType = EditType.DefaultEdit;

                }

                else if ( data[0] .ts_control_type == "Calendar")

                {

                    newCol.EditType = EditType.DatePickerEdit;

                    newCol.Format = "{0:dd-MMM-yyyy}";

                }

                else if ( data[0] .ts_control_type == "ComboBox")

                {

                    newCol.EditType = EditType.DropDownEdit;

                }

                col.Add(newCol);


}

Question , both on how do to that programatically , this like creating a setting screen for grid component.

  1. How to set validation rules ?
  2. How to set datasource if the grid column edit type =  EditType.DropDownEdit;


Thank you




1 Reply

NP Naveen Palanivel Syncfusion Team July 26, 2022 03:49 AM UTC

Hi Dodi,


Greetings from Syncfusion support.


We have checked your query and we have already discussed about this topics detailly in our UG documentation. Kindly refer the documentation link shared.


Refer our UG Documentations :

https://blazor.syncfusion.com/documentation/datagrid/columns#dynamic-column-building


Please get back to us if you need further assistance.


Regards,

Naveen Palanivel


Loader.
Up arrow icon