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
935
Null PrimaryKey in igGrid causing unmapped grid items to transform into first mapping created
posted

Of necessity, I have a list of Mappings but am pulling unmapped lists as part of the result set when the igGrid is setup. Everything works fine (including using dropdown selector for blank field to send to back-end to map to the list displayed across 3 columns), until an unmapped list becomes a mapped list; it then replaces all the unmapped list items until I refresh the page.

What I need is a way to designate a generic identifier to assign for the gridObject.rowId so each row is unique within the grid. I assume the fast track to this solution is using a ternary to assign a generic PrimaryKey when the mapping Guid = Guid.Empty (unmapped).

My formatting is in Razor, as follows:

@(Html.Infragistics().Grid<XeusDesignMapping>()
    .ID(gridId)
    .AutoCommit(true)
    .AutoGenerateColumns(false)
    .AutoGenerateLayouts(false)
    .ResponseDataKey(null)
    .PrimaryKey("MapId")
    .Caption("XEUS Design Mappings")
    .Rest(true)
    .Columns(column =>
    {
        column.For(x => x.MapId).HeaderText("Mapping Id").DataType("string").Hidden(true);
        column.For(x => x.DesignId).HeaderText("Commits Id").DataType("string").Hidden(true);
        column.For(x => x.Design).HeaderText("Commits Design").DataType("string");
        column.For(x => x.ListId).HeaderText("List Id").DataType("string").Hidden(true);
        column.For(x => x.Product).HeaderText("XEUS Product").DataType("string");
        column.For(x => x.Type).HeaderText("Lot Type").DataType("string");
        column.For(x => x.Title).HeaderText("Lot Title").DataType("string");
        if (securityUnLocked) // only Admin can edit and delete xeus design mappings
            column.Unbound("Actions").HeaderText("Actions").Template("<a title='Edit Mapping' href='#' onclick='editRow(\"" + gridId + "\", \"${MapId}\")'>Edit</a> | <a title='Delete Mapping' href='#' onclick='deleteRow(\"" + gridId + "\", \"${MapId}\")'>Delete</a>");
    })
    .Features(features =>
        {
            features.Sorting().Type(OpType.Local);
            features.Filtering().Type(OpType.Local);
            features.Paging().PageSize(20).Type(OpType.Local);
            features.Selection().Mode(SelectionMode.Row);
            features.Resizing();
            features.Updating().EnableAddRow(true).EnableDeleteRow(false)
            .AddClientEvent("rowAdding", "gridHideDefaultRow")
            .AddClientEvent("editRowEnding", "saveEditedRow")
            .ColumnSettings(settings =>
            {   //ColumnKey is the value from the array x above
                settings.ColumnSetting().ColumnKey("Design").EditorType(ColumnEditorType.Combo).Required(true).ComboEditorOptions(co => co.DataSource(Model.Designs).ID("designDD").ValueKey("Name").TextKey("Name").Mode(ComboMode.DropDown));
            });
        })
    .DataSourceUrl("/design/GetXeusDesignMappings/")
    .DataBind()
    .Render()
)

Parents
No Data
Reply
  • 29417
    Offline posted

    Hello Chris, 

    Thank you for posting in our forum. 

    I’m not exactly sure in what manner the values are mapper and whether or not the data source of the grid is changed after the mapping is complete. In general if you change the data source to a new one where the specified primary key field (MapId) has a new unique value, after the grid binds to it the new primary key values will be resolved as the rowId’s.

    If you don’t wish to change the data source, you could instead set the primary key to a column that is Unbound and uses a Formula function to determine it’s value. This is useful if for example you wish to determine the primary key based on the values more than 1 columns (like a composite key) or if you wish to generate the keys based on some other custom logic. For example:

     .PrimaryKey("MyUnboundColumn")
    .Columns(column =>   
            column.Unbound("MyUnboundColumn”) .Formula("generateUniqueKey")

     And then setup the formula function to be used for the primary key values: 

    <script type="text/javascript">

        function generateUniqueKey (row, grid) {

            // return the unique value you generate here

        }

    </script> 

    Let me know if you have any questions or if you need further assistance.

     

    Regards,

    Maya Kirova

Children