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
105
How to avoid displaying the primary key in the grid because of "primary key is missing" error
posted

Hello,

I have created a iggrid. (jquery) (with columns and one primary key because I want to do update operations)

I get the following exception when I try to remove an item in the grid "In order to support update operations after a row was deleted, application should define "primaryKey" in options of igGrid."

I have defined a primary key and the primary key is in my object.
When I add my primary key as first column visible in my grid it works. Ofcourse I don't want to show my primary key to the user.

Is they're a way to avoid this?

Example code:
@(Html.Infragistics()
            .Grid(Model)
            .ID("grid1")
            .PrimaryKey("Id")  
            .UpdateUrl("EditingConversieCodes")            
            .AutoGenerateColumns(false)
            
            //.RenderCheckboxes(true)          
            
            .Columns(column =>
            {                
                //column.For(x => x.Id).HeaderText("Id").DataType("number");
                column.For(x => x.SourceCode).HeaderText("Source Code");
                column.For(x => x.SourceDesc).HeaderText("Source Description");
                column.For(x => x.TargetCode).HeaderText("Target Code");
                column.For(x => x.TargetDescription).HeaderText("Target Desc");
             })                 
             .AutoCommit(true)
            .Features(features =>
            {
                features.Filtering().Type(OpType.Local);
                features.Paging().PageSize(10).Type(OpType.Remote);
                features.Selection().Mode(SelectionMode.Row).MultipleSelection(true);
                features.RowSelectors();
                features.Tooltips().Visibility(TooltipsVisibility.Always);
                features.Updating().EnableAddRow(true)
                    .ColumnSettings(settings =>
                    {
                        //settings.ColumnSetting().ColumnKey("Id").ReadOnly(true);
                        settings.ColumnSetting().ColumnKey("Source_Code").EditorType(ColumnEditorType.Text);
                        settings.ColumnSetting().ColumnKey("Source_Desc").EditorType(ColumnEditorType.Text);
                        settings.ColumnSetting().ColumnKey("Target_Code").EditorType(ColumnEditorType.Text);
                        settings.ColumnSetting().ColumnKey("Target_Desc").EditorType(ColumnEditorType.Text);
                    });
            })
            .DataSourceUrl(Url.Action("DemoGrid"))
            .DataBind().Height("360px").Width("700px").Render())

My class:
    public class ConversieCode
    {
        public Int32 Id { get; set; }
        public string CountryCode { get; set; }
        public string CompanyCode { get; set; }
        public string TypeId { get; set; }
        public string SourceCode { get; set; }
        public string SourceDesc { get; set; }
        public string TargetCode { get; set; }
        public string TargetDescription { get; set; }
}