@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowPaging() .EnableAutoSaveOnSelectionChange(false) .PageSettings(page => { page.PageSize(10); }) .EnableRowHover(false) .EditSettings(edit => { edit.AllowDeleting().AllowEditing().AllowEditOnDblClick(false); }) .ClientSideEvents( eve => eve.QueryCellInfo("rowdata").Create("create")) .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add(); col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add(); col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add(); col.HeaderText("Manage Records").Commands(command => { command.Type(UnboundType.Edit) .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties() { Text = "Edit" }).Add(); command.Type(UnboundType.Delete) .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties() { Text = "Delete" }).Add(); command.Type("Button 3") .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties() { Text = "Save" }).Add(); command.Type("Button 4") .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties() { Text = "Cancel" }).Add(); }).IsUnbound(true).Width(100).Add(); }) )
<script> function rowdata(args) { if (args.data.EmployeeID == 5) { var buttons = $($(args.cell).siblings()[4]).find('button'); for( var i = 0 ; i < buttons.length ; i++) { if ($(buttons[i]).attr("value") == "delete") { $(buttons[i]).remove(); } if ($(buttons[i]).attr("value") == "Button 3") { $(buttons[i]).remove(); } } } else if (args.data.EmployeeID == 4) { var buttons = $($(args.cell).siblings()[4]).find('button'); for (var i = 0 ; i < buttons.length ; i++) { if ($(buttons[i]).attr("value") == "edit") { $(buttons[i]).remove(); } } } } function create(args) { var j = 0, length, first = 0, buttons; for (var i = 0; i < this.element.find(".e-unboundcell").find(".e-unboundcelldiv").length ; i++) { length = $(this.element.find(".e-unboundcell").find(".e-unboundcelldiv")[i]).children().length if (length > first) buttons = $(this.element.find(".e-unboundcell").find(".e-unboundcelldiv")[i]).children().length; first = $(this.element.find(".e-unboundcell").find(".e-unboundcelldiv")[i]).children().length; } var buttons; if (buttons == 4) { $(this.getContentTable().find("colgroup col")[5]).width(150); $(this.getHeaderTable().find("colgroup col")[5]).width(150); } } |
Thanks for the reply.
Please test the solution and update the result to us.
Regards,
Prasanna Kumar N.S.V