Hi Issam,
Thanks for using Syncfusion products.
We have analyzed your requirement for “Grid render based on customer selected in combobox” and created a sample. The sample can be downloaded from following link:
Sample: http://www.syncfusion.com/downloads/support/directtrac/118393/MVCGrid-1279106567.zip
In the provided sample we have used EJDropDown Change event to render the grid record based on customer selected. We have used Ajax post to get the related data from controller then render the grid. Please refer the following code snippet.
[Index] @Html.EJ().DropDownList("select").TargetID("customerList").Width("200px").SelectedItemIndex(0).ClientSideEvents(e => e.Change("getColumns")) </div> <div id="customerList"> <ul> <li>ALL</li> <li>VINET</li> <li>TOMSP</li> <li>HANAR</li> <li>VICTE</li> <li>RICSU</li> <li>HILAA</li> </ul> </div> </div> <div> @(Html.EJ().Grid<object>("Grid") .Datasource(((IEnumerable<object>)ViewBag.datasource1)) .AllowPaging() .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); col.Field("CustomerID").HeaderText("Customer ID").Add(); col.Field("EmployeeID").HeaderText("Employee ID").Add(); col.Field("Freight").Format("{0:c}").Add(); col.Field("ShipCity").HeaderText("Ship City").Add(); })) ) </div> <script> function getColumns(args) { var dropdownValue = $("#select").ejDropDownList("getSelectedValue"); $.ajax({ url: '/Home/DataSource', type: 'GET', data: { "value": dropdownValue }, success: function (data1) { $("#Grid").ejGrid({ dataSource: data1 }); } }) } </script>
[Controller]
public ActionResult DataSource(string value) { var userTemplates = OrderRepository.GetAllRecords(); if (value != "ALL") { IEnumerable<EditableOrder> res = from d in userTemplates where d.CustomerID == value select d; return Json(res, JsonRequestBehavior.AllowGet); } else { IEnumerable<EditableOrder> res1 = from d in userTemplates select d; return Json(res1, JsonRequestBehavior.AllowGet); } } |
Please try the above sample and get back to us if you have any queries.
Regards,
Hi Issam,
We are sorry about the inconvenience caused. Please find the attached sample and code snippet.
Sample: MVCGrid.zip
Query:#1 how to load grid data at the first time, after droplist initialization ?
Your requirement is achieved by using the create event in the Dropdownlist. The create event will call after the dropdownlist initialized and we have loaded the grid data after dropdownlist initialized. Please find the below code snippet.
function create(args) { var value = $("#select").ejDropDownList("getSelectedValue"); $.ajax({ url: '/Grid/DataSource', type: 'GET', data: { "value": value }, success: function (data1) { $("#Grid").ejGrid({ dataSource: data1 }); } }) } |
Query:#2 how to display a busy indicator while data loading. i would add a div contining some indicator, and use jquery to switch some css properties On/Off on the dropdownlist change event and the ajax success function. sound good to you ? or mabe there is an easier way to do that ?
We suggest you to use the ejWaitingPopup control to display the busy indicator over the grid while loading the data, and the waitingpopup is hide after data bound to the Grid.
@Html.EJ().DropDownList("select").TargetID("customerList").Width("200px").SelectedItemIndex(0).ClientSideEvents(e => e.Change("getColumns")) <script> function getColumns(args) { var dropdownValue = $("#select").ejDropDownList("getSelectedValue"); $("#Grid").ejWaitingPopup("show"); $.ajax({ url: '/Grid/DataSource', type: 'GET', data: { "value": dropdownValue }, success: function (data1) { $("#Grid").ejGrid({ dataSource: data1 }); $("#Grid").ejWaitingPopup("hide"); } }) } </script> |
Please let us know if you need any further details regarding this issue and let us know if you have any queries.
Please refer the online documentation to use the waitingpopup:
http://help.syncfusion.com/ug/js/default.htm#!documents/conceptsandfeatures58.htm
Regards,
Balaji Marimuthu