I have the following code that I have created for sorting and searching.
When I add aaSorting
I am able to get the initial table to sort by my specified column. However, on search the table completely goes away, that is removed from the DOM.
Without default aaSorting chained to the dtOptionsBuilder I can search but without default sort order set.
How can I remedy the issue?
Angular Code
$scope.searchOrderHistoryData = function(){
if ($scope.searchQuery.trim() == "")
{
$scope.cancel=false;
return;
}
else{
$scope.IssearchQuery = true;
}
$scope.filterOrderHistoryData = $scope.orderHistory.filter(function(r) {
res = "";
found = true;
for (key in r)
{
if ((key == "OrderId" || key == "OrderName" || key == "TotalCost" || key == "SubmittedDate" || key == "SubmittedBy" || key== "Status") && r[key] != null)
res += angular.lowercase(r[key].toString()) + " ";
}
if (res.indexOf(angular.lowercase($scope.searchQuery)) >= 0)
return true;
return false;
});
}
var orderHistoryCols = {'OrderId':0, 'TotalCost':1, 'SubmittedDate':2, 'SubmittedBy':3, 'Status':4};
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('responsive', true)
.withOption('fnDrawCallback', function () {
$('.dataTables_scrollBody').on("scroll", function(){ //activate when #center scrolls
var left = $('.dataTables_scrollBody').scrollLeft(); //save #center position to var left
$('.dataTables_scrollHead').scrollLeft(left); //set #top to var left
});
})
.withOption('bAutoWidth', false)
//.withOption('sorting', false)
.withOption('scrollY', '450px')
.withOption('aaSorting', [[orderHistoryCols.SubmittedDate, 'desc']]);
Template (HTML)
<table datatable="ng" class="table" dt-options="dtOptions" dt-column-defs="dtColumnDefs">
<thead style="background-color: #d8d8d8;">
<tr>
<!--th ng-hide="true"></th-->
<th>Order #</th>
<th>Total Cost</th>
<th>Submitted</th>
<th>By</th>
<!-- <th>Delivered</th> -->
<th>Status</th>
<th data-orderable="false"></th>
<th data-orderable="false"></th>
</tr>
</thead>
<tbody>
<tr style="font-weight: 100;cursor: pointer;" ng-repeat="data in filterOrderHistoryData">
Table data...
</tr>
</tbody>
</table>