-1

I'm using Angular smart table to display data from my database using Node.js. My problem is that I don't know how to get data from the server with $http.get or $http.post, passing filters and the number of the current page.

This is the documentation about a fake call to the server.

svarog
  • 9,477
  • 4
  • 61
  • 77
Samir Ait
  • 311
  • 1
  • 3
  • 13

1 Answers1

0

You use the GET verb to fetch data (though you can also use POST to carry your parameters on the request body). using a Angular service you could request your data like so

with GET in your service

return $http.get('url/to/data', {
    params: {id: id}}
)

or by using path params

return $http.get('url/to/data/' + id)

in your controller

myHttpService().get(id).then(function(response) {
    $scope.tableData = response.data;
})

go through the $http docs, they are very helpful show several examples for remote server calls

then in your smart table markup

<tbody">
<tr ng-repeat="row in tableData">
    <td>{{row.id}}</td>
    <td>{{row.name}}</td>
</tr>
</tbody>

to get current page, use the st-paginate directive to add a pagination to your

<tr>
    <td colspan="2" class="text-center">
        <div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="5"></div>
    </td>
</tr>

use the st-search directive to filter your data globally or by rows

<th st-sort="id">id</th>
<th st-sort="name">name</th>
svarog
  • 9,477
  • 4
  • 61
  • 77
  • In the documentation example, it's selecting 1000 rows and then filter it and get 10 items according to the current page. What i'm searching for, is how can i get just 10 rows according to the filter and the number of the current page ?? – Samir Ait Dec 19 '15 at 10:22