Hello Infragistics community,
Im using an ASP.Net MVC igGrid. I want my grid to have following behaviour. If I add a new record to my igGrid, i want all my attributes / columns of my grid to be editable.
When i want to update a record of my igGrid, i want some attributes / columns to be readonly. I have tried setting some of my columns to read only. This solved my problem
when i want to update a record. But when i want to add a record, theses attribtes are now readonly.
Is there a way to set the read only attributes separately for adding and editing a record?
thank you very much for the help.
This worked for me! What was confusing was I first found this other post (linked below) but couldn't get it to work I was using MVC helper and attaching a client side event. But I guess that works differently than this method with the delegate? I am just happy it worked
www.infragistics.com/.../538620
Hello Adrian,
I am glad that you find my suggestion helpful.
Thank you for choosing Infragistics components.
Thank you very much Vasya. This solution worked perfectly. Have a nice day!
Having some columns read only when editing and editable when adding row could be accomplished by handling editCellStarting event which is cancellable. In this event, via the ui argument we could check whether the event is raised while new-row-adding and the key of the column that triggered it. If the event is triggered from editing a particular column in an existing row we could cancel it and basically this will make this column read only. For example:
@(Html.Infragistics().Grid<igGridMVCStatApplication.Models.Product>() .ID("grid1") .Width("100%") .AutoCommit(true) .Height("600px") .AutoGenerateColumns(false) .PrimaryKey("Name") .Columns(col => { col.For(c => c.ProductID).HeaderText("ProductID").Hidden(false); col.For(c => c.Name).HeaderText("Name"); col.For(c => c.ReleaseDate).HeaderText("ReleaseDate"); col.For(c => c.ProductNumber).HeaderText("Product Number"); col.For(c => c.Col1).HeaderText("Value 1"); col.For(c => c.Col2).HeaderText("Value2"); col.For(c =>c.Total).HeaderText("Total"); }) .Features(features => { features.Filtering().Mode(FilterMode.Advanced).Type(OpType.Remote); features.Selection().Mode(SelectionMode.Row).MultipleSelection(true); features.RowSelectors().EnableCheckBoxes(true).EnableRowNumbering(false).EnableRowNumbering(true); features.Paging(); features.Updating(); }) .DataSourceUrl(Url.Action("GetData")) .UpdateUrl(Url.Action("OrdersSaveData")) .Render()) <script> //Bind after initialization $(document).delegate("#grid1", "iggridupdatingeditcellstarting", function (evt, ui) { if (!ui.rowAdding && ui.columnKey == "Name" ) { return false; } }); </script> Please test this approach on your side and let me know whether it helps you achieve your requirement.
@(Html.Infragistics().Grid<igGridMVCStatApplication.Models.Product>() .ID("grid1") .Width("100%") .AutoCommit(true) .Height("600px") .AutoGenerateColumns(false) .PrimaryKey("Name") .Columns(col => { col.For(c => c.ProductID).HeaderText("ProductID").Hidden(false); col.For(c => c.Name).HeaderText("Name"); col.For(c => c.ReleaseDate).HeaderText("ReleaseDate"); col.For(c => c.ProductNumber).HeaderText("Product Number"); col.For(c => c.Col1).HeaderText("Value 1"); col.For(c => c.Col2).HeaderText("Value2"); col.For(c =>c.Total).HeaderText("Total"); }) .Features(features => { features.Filtering().Mode(FilterMode.Advanced).Type(OpType.Remote); features.Selection().Mode(SelectionMode.Row).MultipleSelection(true); features.RowSelectors().EnableCheckBoxes(true).EnableRowNumbering(false).EnableRowNumbering(true); features.Paging(); features.Updating(); }) .DataSourceUrl(Url.Action("GetData")) .UpdateUrl(Url.Action("OrdersSaveData")) .Render()) <script> //Bind after initialization $(document).delegate("#grid1", "iggridupdatingeditcellstarting", function (evt, ui) { if (!ui.rowAdding && ui.columnKey == "Name" ) { return false; } }); </script>
Please test this approach on your side and let me know whether it helps you achieve your requirement.