| @{ List<object> commands = new List<object>(); commands.Add(new { type = "Edit", buttonOption = new { iconCss = "e-icons e-edit", cssClass = "e-flat" } }); } @Html.EJS().Grid("EditParam").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).ValidationRules(new { required = "true" }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); . . . . col.HeaderText("Manage Records").Width("150").Commands(commands).Add(); }).AllowPaging().Load("load").EditSettings(edit => { edit.AllowEditing(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Search" }).Render() <script> function load() { this.columns[4].commands[0].buttonOption.click = function (args) { var row = new ej.base.closest(event.target, '.e-row'); // get row element var index = row.getAttribute('aria-rowindex') var grid = document.getElementById('Grid').ej2_instances[0]; var rowData = grid.currentViewData[index]; // get current row Data // you can send POST request or redirect to another page } } </script> |
When I click on the Edit Record menu, do not redirect to another page or maybe exist row use a Edit Mode Dialog Template|
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col =>
{
. . . .
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = "true" }).Add();
col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
}).AllowPaging().ContextMenuItems( new List<object>() {"Edit", "PdfExport", "ExcelExport" }).ContextMenuClick("menuClick").AllowExcelExport(true).AllowPdfExport(true).EditSettings(edit => { edit.AllowEditing(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal).Render()
<script>
function menuClick(args) {
if (args.item.text === 'Edit Record') {
// you can redirect the page as per your requirement.
}
} |
Hi Bhrugen,
Thanks for contacting Syncfusion forum.
We can achieve your requirement using command click event. In
this event we have showed row details and redirected to some action in an MVC
controller using ajax post.
Please refer to the below code block.
|
@{
List<object> commands = new List<object>(); commands.Add(new { type = "userstatus", buttonOption = new { content = "Details", cssClass = "e-flat" } }); }
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => { . . . . . col.HeaderText("Manage Records").Width("150").Commands(commands).Add();
}).AllowPaging().Load("load").CommandClick("commandClick").EditSettings(edit => { edit.AllowEditing(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal);
}).Toolbar(new List<string>() { "Search" }).Render()
<script> function commandClick(args) {
console.log((JSON.stringify(args.rowData))); // display row data details var ajax = new ej.base.Ajax({ type: "POST", url: "/Home/PersonnelList", contentType: "application/json; charset=utf-8", }); var data = JSON.stringify({ Username: 'hello', Password: 123456 });
ajax.send(data).then(); ajax.onSuccess =
result => { console.log(JSON.parse(result)); }; }
</script>
public class MyModel { public string Username { get; set; } public long Password { get; set; } } public JsonResult PersonnelList(MyModel model) {
List<Name> list = new List<Name> { new Name { Text = "Berlin"}, new Name { Text = "Madrid"}, new Name { Text = "Cholchester"} }; return Json(list); } |
Reference link : https://ej2.syncfusion.com/documentation/api/grid/#commandclick
Please get back to us, if you need any further assistance.
Regards,
Thiyagu S