Setting rowId for java script array
Setting rowId for java script array
I'm using DataTables like this:
table = $('#tblRunHistory')
.DataTable({
paging: true,
ajax: {
url: '@Url.Action("GetRunsJavaScriptArray")',
dataSrc: 'Runs',
type: 'GET',
rowId: <???>,
cache: false,
async: true,
data: function(d) {
d.Company = $('#ddlArchiveCompanies').val();
d.TimeZoneOffset = new Date().getTimezoneOffset();
}
},
searching: false,
info: true,
order: [[0, 'desc']],
columns: [
{ title: "Id", searchable: false, data: [0] },
{ title: "Company", searchable: false, data: [1] },
{ title: "State", searchable: false, render: renderState, data: null, className: 'details-control' },
{ title: "Start", searchable: false, data: [3] },
{ title: "End", searchable: false, data: [4] },
{ title: "Candidates", searchable: false, data: [5] },
and
public async Task<ContentResult> GetRunsJavaScriptArray(int timeZoneOffset, string company)
{
var runs = await ManagementServiceClient.GetArchiveRuns(company);
var runArray = new JArray(
runs.ArchiveRuns.Select(run =>
{
var start = run.Start.ToString("d", CultureInfo.CurrentCulture);
var end = run.End.ToString("d", CultureInfo.CurrentCulture);
return new JArray
{
new JValue(run.Id), // 0
new JValue(run.Company),
new JValue(Localize(run.State)),
new JValue(start),
new JValue(end),
new JValue(run.ItoCandidateCount), // 5
new JValue(run.ItoRecordsConsolidated),
new JValue(run.ItDeletedRecordCount),
new JValue(run.PercentArchiveComplete.ToString("N2")),
new JValue(run.State),
new JValue(run.ErrorMessage), // 10
new JValue(run.ItoRecordsRestored),
new JValue(run.ItoRecordsConsolidated > 0 ? (100 * run.ItoRecordsRestored / (decimal)run.ItoRecordsConsolidated).ToString("N2") : "0.00")
};
}));
var runInfo = new JObject(
new JProperty("Runs", runArray),
new JProperty("IsRunning", runs.IsRunning));
return Content(runInfo.ToString(), "application/json");
}
I'm trying to maintain the users selection when the data is refreshed.
How do I configure/set the rowId: property appropriately in this case?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You have the
rowId
option inside the ajax object. It should be within the Datatables object. Something like this:Kevin
Thanks Kevin. It was late. I tried all sorts - in the wrong place