ejGrid How to do show enum types in model?
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
SIGN IN To post a reply.
1 Reply
PK
Prasanna Kumar Viswanathan
Syncfusion Team
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
}
|
Sample: http://www.syncfusion.com/downloads/support/forum/124680/ze/SyncfusionMvcApplication22694865616
Help Documents:
columnTemplate : http://help.syncfusion.com/js/grid/columns#column-template
templateRefresh: http://help.syncfusion.com/js/api/ejgrid#events:templaterefresh
Regards,
Prasanna Kumar N.S.V
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
EA Emir Aydogan
- Jun 22, 2016 02:21 PM UTC
- Jun 23, 2016 09:24 AM UTC