BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hi Roman,
Thanks
for using Syncfusion products.
We have analyzed the code provided by
you, and achieved your requirement by using “ej.parseJSON and the column Format”.
.
The
column format property is used to convert the user format in Grid columns.
Please find the code snippet.
[In
view] @(Html.EJ().DropDownList("drpdown").ClientSideEvents(c=> c.Change("change")).Datasource(ViewBag.data)) @(Html.EJ().Grid
.Datasource((IEnumerable<object>)ViewBag.datasource)
.EditSettings(e
=> { e.AllowAdding().AllowEditing(); })
.ClientSideEvents(c=> c.EndEdit("EndEdit"))
.Columns(col =>
{
col.Field("OrderDate").HeaderText("Order
Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add();
})) |
Since we are using ej.parseJSON method, we need to
serialize the JSON Value after AJAX post success method. ej.parseJSON method helps to serialize the JSON Value in proper way
Please find code snippet.
[in ajax post] <script type="text/javascript">
function
change(args) {
var res =
JSON.stringify(args)
$.ajax({
url: "Home/Data",
type: "POST",
dataType:"json",
data: { data: res },
success: function(result)
{
var obj =
$("#Grid").ejGrid("instance");
obj.dataSource(ej.parseJSON(result.Data));
}
});
}
script> |
[in controller]
public
ActionResult Index()
{
var
drpdata = new NorthwindDataContext().OrdersViews.Select(c =>
c.OrderDate).Distinct().ToList();
ViewBag.data = drpdata;
var
DataSource = new NorthwindDataContext().OrdersViews.ToList();
ViewBag.datasource = DataSource;
return
View();
}
public
ActionResult Data(string data)
{
JavaScriptSerializer
datajson = new JavaScriptSerializer();
var obj =
datajson.Deserialize<DropDownListProperties>(data);
var jsonResult = Json(new NorthwindDataContext().OrdersViews.ToList());
return
Json(jsonResult, JsonRequestBehavior.AllowGet);
} |
For your
convenience We have created a sample and the same can be downloaded from the
below link:
Sample
Location:
http://www.syncfusion.com/downloads/support/directtrac/general/Sample_117336-1653305310.zip
Please
let us know if have any other queries,
Regards,
J.Mohammed
Farook