|
// Button click event function
document.getElementById('update').addEventListener('click', function (args) {
var inputValue = document.getElementById('inputVal').value;
// Ajax request is made to fetch data from back end
var ajax = new ej.base.Ajax({
url: "/Home/GetGridData",
type: "POST",
contentType: "application/json; charset=utf-8",
// Required input values can be sent along with the request
data: JSON.stringify({ inputValue: inputValue }),
});
ajax.onSuccess = result => {
// Grid instance
var gridObj = document.getElementById('Grid').ej2_instances[0];
// The returned result is parsed to JSON format and set as Grid’s data source
gridObj.dataSource = ej.data.DataUtil.parse.parseJson(result);
}
ajax.send();
}) |
|
public JsonResult GetGridData([FromBody]string inputValue)
{
// Here you can return the data based on the input received
return Json(OrdersDetails.GetAllRecords());
} |
|
<div id="target"></div>
@Html.EJS().Dialog("defaultDialog").Visible(false).Header("Get values").ContentTemplate(@<div>
<div>
@Html.EJS().TextBox("inputVal1").Placeholder("Enter value").Render()
</div><div>
@Html.EJS().TextBox("inputVal2").Placeholder("Enter value").Render()
</div>
</div>).ShowCloseIcon(true).IsModal(true).Target("#target").Buttons(ViewBag.DefaultButtons).Width("300px").Render()
</div> |
|
public ActionResult Index()
{
// The dialog button model is defined with click event
List<DialogDialogButton> buttons = new List<DialogDialogButton>() { };
buttons.Add(new DialogDialogButton() { Click = "dlgButtonOKClick", ButtonModel = new DefaultButtonModels() { content = "OK", isPrimary = true } });
buttons.Add(new DialogDialogButton() { ButtonModel = new DefaultButtonModels() { content = "CANCEL" } });
ViewBag.DefaultButtons = buttons;
return View();
}
public class DefaultButtonModels
{
public string content { get; set; }
public bool isPrimary { get; set; }
} |
|
@Html.EJS().Button("normalbtn").Content("Open dialog").Render()
<script>
document.getElementById('normalbtn').onclick = function () {
// EJ2 Dialog instance is retrieved and the dialog is opened using its ‘show’ method
var dialogObj = document.getElementById('defaultDialog').ej2_instances[0];
dialogObj.show();
};
</script> |
|
// Dialog button click event handler
function dlgButtonOKClick(args) {
// The input values are retrieved
var inputValue1 = document.getElementById('inputVal1').value;
var inputValue2 = document.getElementById('inputVal2').value;
// Request is sent to fetch data from service
var ajax = new ej.base.Ajax({
url: "/Home/GetGridData",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ inputValue1: inputValue1, inputValue2: inputValue2 }),
});
ajax.onSuccess = result => {
var gridObj = document.getElementById('Grid').ej2_instances[0];
// The returned JSON result is set as Grid’s data source
gridObj.dataSource = ej.data.DataUtil.parse.parseJson(result);
}
ajax.send();
// The dialog is hidden
var dialogObj = document.getElementById('defaultDialog').ej2_instances[0];
dialogObj.hide();
} |
|
public JsonResult GetGridData([FromBody]string inputValue1, [FromBody]string inputValue2)
{
// Here you can return the data based on the input received
return Json(OrdersDetails.GetAllRecords());
} |
|
@Html.EJS().DropDownList("dropdown").Placeholder("Select a value").Width("300px").PopupHeight("200px").DataSource((IEnumerable<object>)ViewBag.DropData).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Value = "ID", Text = "CustomerID" }).Render() |
|
function onBeforeOpen(args) {
// EJ2 Dropdown value is retrieved
var dropVal = document.getElementById('dropdown').ej2_instances[0].text;
// Request is sent to fetch data from service
var ajax = new ej.base.Ajax({
url: "/Home/GetDialogValue",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ dropValue: dropVal }),
});
ajax.onSuccess = result => {
// The returned result is bound to the input elements
var parsedRes = JSON.parse(result);
document.getElementById('inputVal1').value = parsedRes["input1"];
document.getElementById('inputVal2').value = parsedRes["input2"];
}
ajax.send();
} |
|
public JsonResult GetDialogValue([FromBody]string dropValue)
{
DialogValues res = new DialogValues();
res.input1 = dropValue;
res.input2 = dropValue;
// Here you can return dialog input data based on the dropdown value received
return Json(res);
}
public class DialogValues
{
public string input1 { get; set; }
public string input2 { get; set; }
} |
|
public JsonResult GetDialogValue([FromBody]string dropValue)
{
DialogValues res = new DialogValues();
...
// Here the required Boolean value can be returned
res.isChecked = true;
return Json(res);
}
public class DialogValues
{
public string input1 { get; set; }
public string input2 { get; set; }
public bool isChecked { get; set; }
} |
|
// Dialog beforeOpen event handler
function onBeforeOpen(args) {
var dropVal = document.getElementById('dropdown').ej2_instances[0].text;
// Request is sent to fetch data from service
var ajax = new ej.base.Ajax({ ... });
ajax.onSuccess = result => {
var parsedRes = JSON.parse(result);
...
// The check value(returned from controller) is set as the ‘checked’ property value of the EJ2 Checkbox
document.getElementById('isChecked').ej2_instances[0].checked = parsedRes["isChecked"];
}
ajax.send();
} |