Use data from one datatable to create another datatable?
Use data from one datatable to create another datatable?
Is it possible to create a second datatable by using data from the first data table? I'm on SharePoint Online/Office 365. Using REST, I populated the first datatable with all 'pending' items. In my datatable settings, I added a column for user to 'check' other approved absence requests within the same date range as the current request.
"aoColumns": [
{//check link
"render": function(data, type, row) {
var rowID = row.ID;
var rowEventDate = row.StartDateISO;
var rowEndDate = row.EndDateISO;
return '<a href="javascript:modCheck(' + rowEventDate + "," + rowEndDate + ');">Check</a>';
}
},
When user clicks the [check] link, it should populate another datatable
function modCheck(rowEventDate, rowEndDate) {
var webAbsUrl = _spPageContextInfo.webAbsoluteUrl;
var checkInfo = webAbsUrl + "/_api/web/Lists/getByTitle('AbsenceRequest')/Items?$filter=((StartDateISO ge datetime'" + rowEventDate.toISOString() + "') and (EndDateISO le datetime'" + rowEndDate.toISOString() + "'))&$select=Id, Absentee, RequestType, ActivityType, EventDate, EndDate, Status";
var ajaxAllAbsences = $.ajax({
url: checkInfo,
type: "GET",
dataType: "json",
headers: { "accept": "application/json;odata=verbose" },
success: mySuccessH,
error: myErrHandler
});
});
}
but I can't get it to populate the 2nd table which is located right below the first table.
<table id="tablePending" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th width="30%">Check</th>
<th width="5%">ID</th>
<th width="25%">Name</th>
<th width="20%">Start Date</th>
<th width="20%">End Date</th>
</tr>
</thead>
<tfoot> </tfoot>
</table>
<p> </p><p> </p>
<table id="tableAllAbs" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th width="5%">ID</th>
<th width="20%">Name</th>
<th width="20%">Request Type</th>
<th width="20%">Start Date</th>
<th width="20%">End Date</th>
<th width="15%">Status</th>
</tr>
</thead>
<tfoot> </tfoot>
</table>
Answers
See if this blog example helps.
https://datatables.net/blog/2016-03-25
It shows how to use the row ID of the selected row in the parent table to populate the child table via ajax. If you are not using Editor then you can ignore the Editor portions of the code.
Kevin
Tamras,
Did you get it to work? I am doing exactly what you are doing. Would you be kind enough to share your solution?
I'm not sure whether this will be useful - it was in response to a question earlier this week about transferring data between two tables. They're both local tables, but the transfer method is still relevant.
Cheers,
Colin