Customize model of the Columns.EditType through the Columns.Edit.Params.

How to customize the Columns.Edit.Params?

<ejs-grid allowPaging="true" allowSorting="true" id="FlatGrid" toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Cancel", "Update"})">
    <e-data-manager url="@Url.Action("UrlDatasource", "ServiceProvider")" insertUrl="/Home/Insert" updateUrl="/Home/Update"
                    removeUrl="/Home/Delete" adaptor="UrlAdaptor" crossDomain="true" ></e-data-manager>
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"
                         showConfirmDialog="true" showDeleteConfirmDialog="true"></e-grid-editSettings>
    <e-grid-columns>

        <e-grid-column edittype="dropdownedit" field="PaperSize" headertext="Paper Size" textalign="Right" [email protected]>
            
        </e-grid-column>

        <e-grid-column field="PaperType" headertext="Paper Type" edittype="dropdownedit"></e-grid-column>
        <e-grid-column field="PrintRangeMinimum" headertext=" Page Quantity Minimum" textalign="Right"></e-grid-column>
        <e-grid-column field="PrintRangeMaximum" headertext=" Page Quantity Maximum" textalign="Right" edittype="Numeric"></e-grid-column>
        <e-grid-column field="PrintMode" headertext="Print Mode" edittype="dropdownedit"></e-grid-column>
        <e-grid-column field="PrintOption" headertext=" Print Option" edittype="dropdownedit"></e-grid-column>
        <e-grid-column field="Rate" headertext="Rate in Rs."></e-grid-column>
    </e-grid-columns>
</ejs-grid>

PaperSize is the string[].when is select the row and edit it,the dropdown just shows the options from existing data source and not the edit options,What am i doing wrong?Can you provide the solutions?

5 Replies

LR Logesh Rajappa Syncfusion Team July 17, 2018 11:49 AM UTC

Hi Rachna, 

Thanks for contacting Syncfusion support. 

Query: “the dropdown just shows the options from existing data source and not the edit options” 

We have analyzed your query and you can customize model of the Columns.EditType through the Columns.Edit.Params. From the query we suspect that string[] datatype is used for datasource, so we suggest to use object type to bind datasource to the grid component . In the below sample, we have used cell edit type and its params to customize properties of the dropdownedit. In the params, dataSource is used to bind the created dataSource to the dropdownedit and fields property is used to get the text and value of the field. Please refer to the below sample and help documentation. 

[index.cshtml] 
... 
<ejs-grid id="Grid" allowSorting="true" toolbar="@(new List<string>() { "Add", "Update", "Cancel" })" allowPaging="true"> 
        <e-data-manager url="/Home/UrlDatasource/" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager> 
... 
        <e-grid-columns> 
... 
            <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" editType = "dropdownedit" edit = "@(new { @params = new { dataSource = ViewBag.DropDown ,  
                                         fields= new { text = "ShipCountry", value ="ShipCountry"} }})" ></e-grid-column> 
...        
 </e-grid-columns> 
    </ejs-grid> 
</div> 

[HomeController.cs] 
... 
public IActionResult Index() 
        { 
            var shipcountry = data.GetAllRecords(); 
            ViewBag.DropDown = shipcountry; 
            return View(); 
        } 
... 
public class data                                    //Creating datasource for dropdownedit 
    { 
        public static List<data> ship = new List<data>(); 
        public data() 
        { 
 
        } 
        public data(string ShipCountry) 
        { 
            this.ShipCountry = ShipCountry; 
        } 
        public static List<data> GetAllRecords() 
        { 
            if (ship.Count() == 0) 
            { 
 
                ship.Add(new data("ALFKI")); 
                ship.Add(new data("ANATR")); 
                ship.Add(new data("ANTON")); 
                ship.Add(new data("BLONP")); 
                ship.Add(new data( "BOLID")); 
 
            } 
            return ship; 
        } 
 
        public string ShipCountry { get; set; } 
    } 
} 
... 




If we have misunderstood your query, please get back to us with more details or information. It will help us to provide better solution as soon as possible. 

Regards, 
Logesh Rajappa


AN Andrew February 12, 2019 05:33 PM UTC

What if I want to bind the dropdown to an enum?


PS Pavithra Subramaniyam Syncfusion Team February 14, 2019 06:01 AM UTC

Hi Andrew, 

Greetings from Syncfusion. 

Query : I want to bind the dropdown to an enum? 

We have analyzed your query and prepared a sample to provide enum data to the dropdown edit column in the grid. Please refer to the below sample and code snippet for your reference, 

[controller.cs] 
... 
public IActionResult Index() 
        { 
            ... 
            var enumData = Enum.GetValues(typeof(OrderList)).Cast<Enum>().Select(value => new { 
                (Attribute.GetCustomAttribute(value.GetType().GetField(value.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute).Description, 
                value 
            }).OrderBy(item => item.value).ToList(); 

            ViewBag.DropDown1 = enumData
... 
        } 

        public enum OrderList 
        { 
            [Description("ALFKI")] 
            order1 = 1, 
            [Description("ANATR")] 
            order2 = 2, 
            [Description("ANTON")] 
            order3 = 3, 
            [Description("BLONP")] 
            order4 = 4, 
            [Description("BOLID")] 
            order5 = 5 
        } 
… 
[.cshtml] 

... 
            <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" editType="dropdownedit" edit="@(new { @params = new { dataSource = ViewBag.DropDown, Query = "new ej.data.Query()", fields= new { text= "ShipCountry", value ="ShipCountry" } } })" ></e-grid-column> 
... 


Please get back to us for further assistance. 
 
Regards,  
Pavithra S. 
 



AR Arthur February 10, 2020 01:49 PM UTC

This vinculation in enum not working in sample project.


DR Dhivya Rajendran Syncfusion Team February 11, 2020 01:23 PM UTC

Hi Arthur, 

Thanks for contacting Syncfusion support. 

Before procceding your query, could please share the below details, which will help us to validate and provide a better solution as soon as possible. 

  1. Explain or exact scenario about your problem,
  2. Share the Grid and server side code example
  3. If possible, replicate the reported problem with our previously provided(last update) sample.

Regards, 
R.Dhivya 


Loader.
Up arrow icon