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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ejGrid How to do show enum types in model?

Thread ID:

Created:

Updated:

Platform:

Replies:

124680 Jun 22,2016 02:21 PM UTC Jun 23,2016 09:24 AM UTC JavaScript 1
loading
Tags: ejGrid
Emir Aydogan
Asked On June 22, 2016 02:21 PM UTC

hi ,
i have problem with enum types pull model in ejgrid.

BudgetTypes = [ { value: 0, text: "Cost" }, { value: 1, text: "Revenue" }, ];

columns: [

{field: "Type", headerText: "Type", width:"50",editType: ej.Grid.EditingType.Dropdown , dataSource:BudgetTypes, fields: { id: "value", text: "text"}},

 ]
as you see an example i get local data but i want to get model data. how i do?  I'd like you to answer this question
Best Regards 

Prasanna Kumar Viswanathan [Syncfusion]
Replied On June 23, 2016 09:24 AM UTC

Hi Emir, 

Thank you contacting Syncfusion support.  

We have achieved your requirement using columnTemplate feature and TemplateRefresh event. HTML templates can be specified in templateproperty of the particular column as a string (HTML element) or ID of the template’s HTML element. TemplateRefresh event triggers when we refresh the template column element in Grid.  
 
In the templateRefresh event, we have bound DataSource for the DropDown list.    
 
Please refer to the below Help document, code example and sample.    
 

<script type="text/x-jsrender" id="columnTemplate"> 
    <input class="data" type="text" /> 
</script> 
 
<div id="Grid"></div> 
 
<script type="text/javascript"> 
 
    $(function () { 
        $("#Grid").ejGrid({ 
            // the datasource "window.gridData" is referred from jsondata.min.js 
            dataSource: window.gridData, 
            allowPaging: true, 
            templateRefresh : "templaterefresh", 
             
            columns: [ 
                     { headerText: "Drop Down", template: "#columnTemplate", textAlign: "center", width: 110 }, 
                     ---------------------------------- 
           ] 
        }); 
    }); 
    var data =   @(Html.Raw(Json.Encode(ViewData["EmployeeID"]))); 
 
    function templaterefresh (args) { 
 
        $(args.cell).find(".data").ejDropDownList({ 
            dataSource: data, 
            text: "Nr", 
            value:"0" 
        }); 
    } 
    </script> 
--------------------------------------------------------- 
Grid Controller 

public ActionResult GridFeatures() 
        { 
            ViewData["EmployeeID"] = EmployeeID; 
            return View(); 
        } 
 
        public class DMSerial : IDataSourceSerializer 
        { 
            public string Serialize(object obj) 
            { 
                var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj); 
                return str; 
            } 
        } 
 
        public List<object> EmployeeID 
        { 
 
            get 
             
            { 
                var EmployeeID = new List<object>(); 
                Array itemNames = System.Enum.GetNames(typeof(UnitOfMeasure)); 
                foreach (String name in itemNames) 
                { 
                    Int32 value = (Int32)Enum.Parse(typeof(UnitOfMeasure), name); 
                    ListItem listItem = new ListItem(name, value.ToString()); 
                    SerializeObject serialize = new SerializeObject(); 
                    var list = serialize.SerializeToJson(listItem.Text, listItem.Value); 
                    EmployeeID.Add(new { value = listItem.Value, text = listItem.Text }); 
                } 
                return EmployeeID; 
            } 
        } 
        public class EmployeeDetails 
        { 
             [EnumDataType(typeof(UnitOfMeasure))] 
            public UnitOfMeasure Unit { get; set; } 
        } 
 
        public enum UnitOfMeasure 
        { 
           
            Nr = 0, 
      
            Kg = 1, 
           
            g = 2, 
 
            l = 3 
        } 



Help Documents: 



Regards, 
Prasanna Kumar N.S.V 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;