AngularJS: Smart Table global search does not work with this data

0

I have the following problem that I apply Smart Table of angular. I get the records in this way

$http.get('../ws/usuarios').success(function(datas)
    {
        $scope.rowCollection = datas.records;
        console.log($scope.rowCollection);
    });

and here my table shows all the records well, but when using the global search, it does not work. I do it as it is in the documentation. I do not know what my mistake will be.

Table:

<div class="panel-body">            
    <table st-table="rowCollection" class="table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th st-sort="id">#</th>
                <th st-sort="nombre1">Nombre</th>
                <th st-sort="apellido1">Apellido</th>
                <th st-sort="usuario">Usuario</th>
                <th>Tipo de usuario</th>
                <th>Acciones</th>
            </tr>
            <tr>
                <th colspan="6"><input st-search placeholder="Busqueda" class="input-sm form-control" type="search"/></th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="row in rowCollection">
                <td>{{$index+1}}</td>
                <td>{{row.nombre1}}</td>
                <td>{{row.apellido1}}</td>
                <td>{{row.usuario}}</td>
                <td>{{row.idtipousuario}}</td>
                <td>
                    <button class="btn btn-icon btn-info" ng-click="openModal(row,'modal-2', 'lg');"><i class="fa-edit"></i></button>
                    <button class="btn btn-icon btn-red" ng-click="openModal(row,'modal-3', 'lg');"><i class="fa-remove"></i></button>  
                </td>   
            </tr>
        </tbody>
    </table>
</div>

Here the search text box

<th colspan="6"><input st-search placeholder="Busqueda" class="input-sm form-control" type="search"/></th>

according to the documentation with the property st-search , you would apply the search, but nothing.

    
asked by JG_GJ 12.03.2017 в 07:24
source

1 answer

1

Friend, for the global search to work for you (according to the SmartTable documentation), you must add st-safe-src to the table tag

<table st-table="displayedCollection" st-safe-src="collection" class="table table-striped">...</table>

If you check the line that I have set, you will notice that st-table is referencing displayedCollection , which is a "copy" of your base source (in this case rowCollection ); I imagine they are doing this to keep your original data source intact.

So summarizing, st-table is the collection where the search will be made and st-safe-src is your original collection.

Here is an example in Plunker

    
answered by 15.03.2017 / 17:23
source