| <div> <ejs-grid id="Grid" detailTemplate="#detailtemplate"> <e-grid-columns> . . . </e-grid-columns> </ejs-grid> </div> <script type="text/x-template" id="detailtemplate"> <table class="detailtable" width="100%"> . . . </table> </script> |
| <div> @{ List<object> commands = new List<object>(); commands.Add(new { buttonOption = new { content = "Details", cssClass = "e-flat e-details" } }); } @Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => { . . . col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add(); col.HeaderText("Manage Records").Width("160").Commands(commands).Add(); }).AllowPaging().DataBound("bound").AllowSorting().PageSettings(page => page.PageSize(10)).Render() </div> <script> function bound(e) { var ele = document.getElementsByClassName("e-grid")[0] ele.addEventListener('click', function (e) { //click event for command button if (e.target.classList.contains('e-details')) { var grid = document.getElementById('Grid').ej2_instances[0]; var rowObj = grid.getRowObjectFromUID(ej.base.closest(e.target, '.e-row').getAttribute('data-uid')); var data = rowObj.data; alert(JSON.stringify(data)); } }); } </script> |