Set datagrid column when datasource is a simple list

Hi. How can I display the text for this datasource in the first column of this grid?

@{

List<object> commands = new List<object>();
        commands.Add(new { type = "Edit", buttonOption = new { iconCss = "e-icons e-edit", cssClass = "e-flat" } });
        commands.Add(new { type = "Delete", buttonOption = new { iconCss = "e-icons e-delete", cssClass = "e-flat" } });
        commands.Add(new { type = "Save", buttonOption = new { iconCss = "e-icons e-update", cssClass = "e-flat" } });
        commands.Add(new { type = "Cancel", buttonOption = new { iconCss = "e-icons e-cancel-icon", cssClass = "e-flat" } });


    var myList = new List<string>{"text 1", "text 2", "text 3"};

}

<ejs-grid id="myGrid" dataSource='"myList">

            <e-grid-columns>

                <e-grid-column field="???"></e-grid-column>

                <e-grid-column headerText="" commands="commands"></e-grid-column>

            </e-grid-columns>

        </ejs-grid>


1 Reply 1 reply marked as answer

RR Rajapandi Ravi Syncfusion Team July 22, 2022 12:59 PM UTC

Hi David,


Greetings from Syncfusion support


We have checked your shared information and we could see that you are maintaining string array for Grid datasource, by default the Grid supports the JSON object data. So we suggest you resolve the problem by defining JSON data. Please refer the below API and documentation for more information.


API: https://ej2.syncfusion.com/documentation/api/grid/#datasource


Documentation: https://ej2.syncfusion.com/aspnetcore/documentation/grid/data-binding/data-binding


Regards,

Rajapandi R


Marked as answer
Loader.
Up arrow icon