My experiments with the Grid control revealed that the primary key must be either an integer or a string. I would like to use the grid to display objects stored in a MongoDB database, having the primary keys of type ObjectId, as follows:
public class ClientModel
{
public ObjectId Id { get; set; }
public string Name { get; set; }
... some other fields ...
}
The grid definition in the .cshtml file is as follows:
<ej-grid id="ClientGrid" allow-paging="true">
<e-datamanager json="(IEnumerable<object>)ViewBag.DataSource" remove-url="@Url.Action("NormalDelete")" adaptor="remoteSaveAdaptor" />
<e-edit-settings allow-deleting="true" edit-mode="@(EditMode.Normal)"></e-edit-settings>
<e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() { "add", "edit", "delete", "update", "cancel" })"></e-toolbar-settings>
<e-columns>
<e-column field="Id" header-text="Client ID" is-primary-key="true" text-align="Right" width="75"></e-column>
<e-column field="Name" header-text="Name"></e-column>
< ... some other columns ... >
</e-columns>
</ej-grid>
The exception I get upon displaying the grid is:
Object doesn't support property or method 'replace'
and the stack trace is:
t.gridFeatures.edit._htmlEncode [ej.web.all.min.js] Line 10
t.gridFeatures.edit._getPrimaryKeyValues [ej.web.all.min.js] Line 10
t.gridFeatures.edit.deleteRow [ej.web.all.min.js] Line 10
t.gridFeatures.edit._toolbarOperation [ej.web.all.min.js] Line 10
The workaround I have found is to add a computed property to ClientModel and return the Id as a string on the fly. This is more like a hack and I was wondering whether there was an alternative.