External filter in ng-table

Asked

Viewed 247 times

0

I’m new to using Angularjs and ng-table and I’m having a little problem.

I want to learn how to create filters outside the generated table, but I couldn’t find anything on their website "http://ng-table.com".

If it makes a difference, the filter I want to create is a title filter, but outside the tag "table".

My code is working fine, but I want to make an external filter.

JS Code

TemasCtrl.$inject = ['$http', '$resource', 'ngTableParams', '$timeout'];

function TemasCtrl($http, $resource, ngTableParams, $timeout) {

    var temas = this;

    temas.carregarTabela = function () {

        var Api = $resource('/temas');

        temas.loading = true;

        temas.tableParams = new ngTableParams({
            page: 1,
            count: 10,
            sorting: {
                name: 'asc'
            },
            filter: {}
        }, {
            total: 0,
            getData: function ($defer, params) {
                Api.get(params.url(), function (data) {

                    $timeout(function () {

                        params.total(data.total);
                        $defer.resolve(data.itens);

                    }, 500);
                });
            }
        });
    }

}

HTML code

<div class="ui attached segment" ng-init="temas.carregarTabela()">

     <table ng-table="temas.tableParams" show-filter="true" class="ui selectable compact table">
          <tbody>
               <tr ng-repeat="tema in $data">
                    <td class="ui center aligned collapsing" data-title="'ID'" filter="{ 'id': 'text' }">{{ tema.id }}</td>
                    <td class="ui collapsing" data-title="'Slug'" filter="{ 'slug': 'text' }">{{ tema.slug }}</td>
                    <td data-title="'Título'" filter="{ 'titulo': 'text' }">{{ tema.titulo }}</td>
               </tr>
          </tbody>
     </table>
</div>

Thanks in advance for the help!

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.