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() )
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
This wasn't really working for me. I tried using a global int and incrementing it in the associative function, but none of the rows was recognized. Then I added it as the rowId for the row, since our implementation of igGridUpdating is as follows:
editRow = function(gridId, rowId) { $('#' + gridId).igGridUpdating('startEdit', rowId, 1); if (typeof adjustEditRowOptions === "function") adjustEditRowOptions(); };
I still got errors about values not correctly passed around or objects not existing.
I wound up binding the ListId as the PrimaryKey since it isn't repeated in the table. It won't be an issue since the structure is such that there will only ever be one instance of each ListId, despite infinite copies of the Design/DesignId being allowed.
I would still like to see a working implementation of the above suggestion. For reference, the unbound column holding the edit/delete buttons looks like this in the code:
column.Unbound("Actions").HeaderText("Actions").Template("<a title='Edit Design' href='#' onclick='editRow(\"" + gridId + "\", \"${ListId}\")'>Edit</a> | <a title='Delete Design' href='#' onclick='deleteRow(\"" + gridId + "\", \"${ListId}\")'>Delete</a>");
I’ve attached a sample for your reference with the previously suggested implementation.
5852.GridWithUnboundColumn.zip
Please refer to it and let me know if you have any questions.
Note that the data type of the generated value should match the type you use when calling the igGrid API methods. So if for example the generated values are type number (1,2,3 etc.) but you are passing the value as string and calling the API methods with the string values (“1”, “2”, “3” etc.) then an error would be thrown as there would be no primary key field matching that value.
Let me know if you have any additional questions or if you require additional assistance.
That makes sense. The fields we use in this sheet are Guids and Strings.
Thanks for your time.
I am glad that you find Maya`s suggestion helpful.
Thank you for using Infragistics components!