Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Total Count of Data in Pagination #152

Open
kevintanhongann opened this issue Dec 12, 2017 · 2 comments
Open

Feature Request - Total Count of Data in Pagination #152

kevintanhongann opened this issue Dec 12, 2017 · 2 comments

Comments

@kevintanhongann
Copy link

I'm working with Grails JSON Views and discovered that it's not configurable in a few ways.

  1. Count of the total rows of data cannot be enabled in jsonapi.render(). If I don't know the total count of the data, how can I construct my pagination view in pure html format such as this:

screen shot 2017-12-12 at 2 23 52 pm

I can make another API call to specifically know the count of my rows of data. But if this can be enabled and be shown in the json output would be better.

{
      data: [],
      links: {},
      total: '40'
}

@kevintanhongann kevintanhongann changed the title non-HAL Pagination needs to be improved Feature Request - Count of Data in Pagination Dec 12, 2017
@kevintanhongann kevintanhongann changed the title Feature Request - Count of Data in Pagination Feature Request - Total Count of Data in Pagination Dec 12, 2017
@jameskleeh
Copy link
Collaborator

The only place this could be put is in the meta object

@osscontributor
Copy link
Member

osscontributor commented Jul 16, 2018

One way to do it is shown in the project at https://github.com/jeffbrown/issue152.

import demo.Widget
import grails.gorm.PagedResultList

model {
    PagedResultList<Widget> widgetList
}

json {
    total widgetList.totalCount
    data tmpl.widget(widgetList)
}

(note that total increases from 100 to 101 after the POST)

$ curl http://localhost:8080/widget
{"total":100,"data":[{"id":1,"name":"Widget 0"},{"id":2,"name":"Widget 1"},{"id":3,"name":"Widget 2"},{"id":4,"name":"Widget 3"},{"id":5,"name":"Widget 4"},{"id":6,"name":"Widget 5"},{"id":7,"name":"Widget 6"},{"id":8,"name":"Widget 7"},{"id":9,"name":"Widget 8"},{"id":10,"name":"Widget 9"}]}
$ 
$ curl -X POST -d '{"name":"Some New Widget"}' -H "Content-Type: application/json" http://localhost:8080/widget
{"id":101,"name":"Some New Widget"}
$ 
$ curl http://localhost:8080/widget
{"total":101,"data":[{"id":1,"name":"Widget 0"},{"id":2,"name":"Widget 1"},{"id":3,"name":"Widget 2"},{"id":4,"name":"Widget 3"},{"id":5,"name":"Widget 4"},{"id":6,"name":"Widget 5"},{"id":7,"name":"Widget 6"},{"id":8,"name":"Widget 7"},{"id":9,"name":"Widget 8"},{"id":10,"name":"Widget 9"}]}
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants