We have a DataTable which contains data like so:
<table class="display" id="invoiceTable">
<thead>
<tr id="headingRow">
<th>Sys_InvoiceID</th>
<th>Details</th>
<th>Inc.In Turnover</th>
<th>Status</th>
<th>Invoice No.</th>
<th>Invoice Date</th>
<th>Type</th>
<th>Supplier Invoice No.</th>
<th>Account Number</th>
<th>Supplier</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Details1</td>
<td>Yes</td>
<td>Issue</td>
<td>500</td>
<td>18/08/2016</td>
<td>Type1</td>
<td>111111</td>
<td>56565</td>
<td>SupplierID</td>
</tr>
</tbody>
</table>
And the jQuery to initialise the DataTable looks like this:
$(document).ready(function(){
var table = $('#invoiceTable').DataTable({
dom: 'rti',
ajax: {
"url": filterDataLink,
},
serverSide: true,
"order": [[5, 'asc']],
searching: false,
paging: true,
scrollX: true,
scrollY: "75vh", //70% of the window height
processing: false,
ordering: true,
scroller: {
loadingIndicator: true,
displayBuffer: 20
}
});
});
And the C# method looks like this:
public string FilterData(TableFilterItem tableFilterItem)
{
try
{
if (tableFilterItem.ColumnOrder == null || tableFilterItem.ColumnOrder.First() == null)
tableFilterItem.ColumnOrder = new List<ColumnOrder>();
SessionModel sessionModel = (SessionModel)Session["Filters"];
DataTableReturn output = _homeManager.ReturnDataTableSession(sessionModel, tableFilterItem);
Session["Filters"] = output.SessionModel;
return output.DataTable;
}
catch (Exception ex)
{
return "An error occurred, please try later! " + ex.Message;
}
}
TableFilterItem looks like this:
public class TableFilterItem {
public TableFilterItem() {
}
public int Start { get; set; }
public int Length { get; set; }
public int Draw { get; set; }
public int order { get; set; }
}
We also have another AJAX call later in the application which calls the C# method to return data. When clicking on a column it calls the method but I don't know what property to have in the method which would be populated by DataTables so I can access the sorting.
EDIT: It's initialise not initialize. I'm not American.