1

I am stuck with ng-table filtering.

The sample in http://ng-table.com/#/filtering/demo-nested-property says to use this syntax into markup, showing below. But it doesn't work when I try to make the filtering in my controller(code below).

Using the sample of the site when I get the filter object in controller, I get {tabela_tuss.descricao:"asda"}. The correct will be: {tabela_tuss:{descricao:"asda"}}

I have:

//markup:

<table ng-table="tableParams" class="table table-bordered table-striped table-condensed">
 <tr ng-repeat="row in $data track by row._id">
 <td  data-title="'Descrição'" filter="{ 'tabela_tuss.descricao': 'text' }" >{{row.tabela_tuss.descricao}}</a></td>
  </td>
 </tr>
</table>

In order to work, I need a filter as:

 filter="{ 'tabela_tuss:{'descricao': 'text' }}"

But, if I do that, I get an error in angular as:

angular.js:14328 Error: [$parse:syntax] Syntax Error: Token '}' is an unexpected 
token at column 37 of the expression [{ 'tabela_tuss:{descricao': 'text'} }] 
starting at [}].

I need that filter to use in my controller: //controller

dataService.getProcedimentos().then(function (response){
        $scope.data=response.data;
        $scope.tableParams = new NgTableParams({
            page: 1,            // show first page
            count: 10,
            sorting: {
              nome: 'asc'
            }
        }, 
        {        getData: function(params) {
                  var sdata = params.sorting() ? $filter('orderBy')($scope.data, params.orderBy()) : $scope.data;
                  sdata = params.filter() ? $filter('filter')(sdata, params.filter()) : sdata;
                  //sdata = params.filter() ? $filter('filter')(sdata, {tabela_tuss:{descricao:'B'}}) : sdata;
                  console.log(params.filter());
                  params.total(sdata.length);
                  sdata = sdata.slice((params.page() - 1) * params.count(), params.page() * params.count());
                  return sdata;
                }
        }
        );
      });

My data sample is:

data:[
{_id: "5927043517e34011e48d8444", 
nome: "proced 1",
tabela_tuss:{id:1,descricao:'descr test'}
]

1 Answer 1

2

You are getting parse syntax error because there is a syntax error. Change your filter from

       filter="{ 'tabela_tuss:{'descricao': 'text' }}"

to

       filter="{ 'tabela_tuss':{'descricao': 'text' }}" 
Sign up to request clarification or add additional context in comments.

1 Comment

I agree with you. I alread had tested it. But if I use it, I get an other error: "angular.js:14328 TypeError: Cannot read property 'indexOf' of undefined at t.getTemplateUrl (ngTableFilterConfig.ts:81) at fn (eval at compile (angular.js:15156), <anonymous>:4:306) at Scope.$digest (angular.js:17806) at Scope.$apply (angular.js:18080) at done (angular.js:12210) at completeRequest (angular.js:12436) at XMLHttpRequest.requestLoaded (angular.js:12364)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.