0

I have a dataset (rendered in Angular Datatables) that I want to display for items that are categorized by "filterTags".

Each time I run a query I need to have to first fetch new data based on fitlerTag.

The problem is, when I sort data, I keep getting the initial filterTag name as the criteria to filter and the dataset is not updated.

How do I get the table respond when clicking the top two filterTag buttons as seen in the plunkr?

Table Repeat Code - Data Set is based on a fitlerTag

ng-repeat="data in Data| filter:{ TagName: filterTag, TagId: filterId} | filter:searchText"

Data Source Fetch Function

var getData= function(){
  $scope.Data= service.getData().query();
}

Code to call getData() called on visit to page

if(path == "/some/path"){
  getData();
}

EDIT

Please see plunkr

https://plnkr.co/edit/Kzw3zO673ORPY1xlWw9p?p=preview

As of now, I can't figure out why

$scope.filterTag = "TYPE 1";

or

$scope.filterTag = "TYPE 2"; works

But the following call produces no results in the table, empty table is shown in my plunkr example.

  $scope.selectTag = function(tag){
    $scope.filterTag = tag;
}
Vahe
  • 1,699
  • 3
  • 25
  • 76
  • Can you post your code on Plunker? It is kind of hard to diagnose your issue by just looking at your code snippets. Here's an example of how to do it from a similar question: http://stackoverflow.com/questions/27953331/angularjs-ng-repeat-filter-by-id – Latin Warrior Oct 08 '16 at 12:17
  • I believe what I am dealing with is that with angular-datatables I need to modify the default sort function. Nowhere do I see any sort code in the html or in the controller (angular controller). How do I modify the sort behavior or catch when I sort via a callback? In the meantime I will attempt to create a plunkr.. – Vahe Oct 08 '16 at 15:50
  • I tried to replicate the exact problem. It is very close. Now I have it almost as it is behaving in my setup, but not quite. Please see https://plnkr.co/edit/Kzw3zO673ORPY1xlWw9p?p=preview – Vahe Oct 08 '16 at 23:26
  • I am using an updated anuglar-datatables, but I uncovered a possibleissue similar to this post https://github.com/l-lin/angular-datatables/issues/254 – Vahe Oct 09 '16 at 18:38

1 Answers1

0

An upgrade to 1.10.12 (datatables) fixed the issue.

//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js

I also had to update the filter to be a custom filter instead of inline as I had in my question.

  //Initial Value
$scope.filterTag = "TYPE 1";

$scope.dtInstance = {};

  $scope.filteredData = $scope.items.filter(function(r) {
    var tag = (typeof $scope.filterTag === undefined)? "TYPE 1"  : $scope.filterTag;
    var show = r.TagName == tag;
    return show;
});



 var update = function(){
  $scope.filteredData = $scope.items.filter(function(r) {
     var tag = (typeof $scope.filterTag === undefined)? "TYPE 1"  : $scope.filterTag;
    var show = r.TagName == tag;
    return show;
});
}

Working example

https://plnkr.co/edit/NI6ixwlUT82s1MpBvMRg?p=preview

Vahe
  • 1,699
  • 3
  • 25
  • 76