Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
135
igGrid - readonly attributes for updating a record, non-readonly attributes for adding a record
posted

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. 

ReadOnly on columns

Is there a way to set the read only attributes separately for adding and editing a record?

thank you very much for the help.

 

Parents
  • 17590
    Verified Answer
    Offline posted

    Hello Adrian,

    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.

Reply Children
No Data