Hi, I used the solution at this post (https://datatables.net/forums/discussion/comment/121148/#Comment_121148) to update my dataTable to allow my checkboxes to show a Yes or No value when exporting to Excel. However, this solution also removes the text I have showing in those fields, I am showing an expiration date if the checkbox comes back true.
Can someone help me figure out how to keep the yes/no values, and also the text?
Here is my dataTable including Razor syntax:
<td role="gridcell">
@Html.CheckBoxFor(modelItem => item.NotaryPublic, new { @id = "Notary Public-" + item.PID, @title = "Notary Public", @disabled = "disabled" })
@if (item.NotaryPublic == true)
{
var npExpDate = string.Concat(string.Format(item.NotaryPublicExpirationDate.AsDateTime().ToString("MM-dd-yy")));
var text = String.Concat(" (Exp Date: " + npExpDate + ")");
@Html.DisplayFor(modelItem => text)
}
</td>
Or, if you prefer, here is the HTML:
<td role="gridcell">
<input checked="checked" id="CPR Trained-929" name="item.CPRTrained" title="CPR Trained" type="checkbox" value="true" /><input name="item.CPRTrained" type="hidden" value="false" />
(Exp Date: 05-20-21)
</td>
columnDefs: [
{ orderable: false, targets: 'no-sort' },
{
render: function (data, type, row) {
var i = (type === 'export' ? ($(data).prop("checked") === true ? 'Yes' : 'No') : data);
return i;
},
targets: [12, 13, 14, 15, 16]
}
]
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide. (note, back ticks should be on their own lines)