Add support for DT_RowId property.
sbroccardi opened this issue · 3 comments
Can we add support to specify DT_RowId?
If I understand your request correctly, I assume you would like to map a property in your model or projection to DT_RowId. This can be achieved in multiple ways.
-
Use a read only property called DT_RowId in your class. see: https://github.com/garvincasimir/csharp-datatables-parser/blob/master/src/aspnet-core-sample/Models/Person.cs
-
Use a serialization attribute
[JsonProperty(PropertyName = "DT_RowId ")]
public Id { get; set; }
- Modify the data in rowCallback
$('#example').dataTable( {
"rowCallback": function( row, data, index ) {
data.DT_RowId = data.Id
}
} );
Not 100% sure about 3. If not it can be done in the ajax callback.
You're right about that. Option 1 and 2 run smoothly but option 3 when using server-side processing does not work. A fourth way works by specifying the rowId option, like this:
$('#example').dataTable( {
rowid: 'Id',
columns: [
{ data: "Id", title:"ID" },
{ data: "FirstName", title:"First Name" },
{ data: "LastName", title:"Last Name" },
{ data: "BirthDate", title:"Birth Date" },
{ data: "Weight", title:"Weight" },
{ data: "Height", title:"Height" },
{ data: "Children", title:"Children" }
]
});
Thank you so much for the advice. If you agree, the second and fourth way could be added to the readme, since it is a very common function when using data tables and your parser. Thank you very much and good work with the parser.
Added 4 to Readme. Happy you find the project useful. Thank you.