Question

Sorting & paging

  • 17 July 2017
  • 8 replies
  • 409 views

I am having trouble getting sorting to work, also is there anyway to page results ?


axios.post('https://vroom.looker.com:19999/api/3.0/login?client_id=' + REACT_APP_LOOKER_KEY + '&client_secret=' + REACT_APP_LOOKER_SECRET)

.then(response => {


var lookerToken = response.data.access_token


var vin = '123'
var firstName = 'john'
var lastName = 's'

var vinWildCard = encodeURIComponent(`%${vin}%`)
var firstNameWildCard = encodeURIComponent(`%${firstName}%`)
var lastNameWildCard = encodeURIComponent(`%${lastName}%`)

var sort = 'inventory_table.vin+desc+1'

var limit = 10;

var queryString = `fields=inventory_table.vin,inventory_table.year,sales_table.customer_first_name,sales_table.customer_last_name&f[inventory_table.vin]=${vinWildCard}&f[sales_table.customer_first_name]=${firstNameWildCard}&f[sales_table.customer_last_name]=${lastNameWildCard}&sorts={sort}&limit=${limit}&access_token=${lookerToken}`;

var time = Date.now()

axios.get(`https://vroom.looker.com:19999/api/3.0/queries/models/Operations_Reporting/views/inventory_table/run/json?${queryString}`)
.then(function(response){

console.log(`query took ${Date.now() - time}`)

console.log(response.data);
console.log(response.status);
});

})


8 replies

Userlevel 3
Badge

Hey there @emmett!


I see a couple of things in your code snippet that could be causing the problems you’re having, but rather than take a shot in the dark, can you repost the error that you’re getting in its entirety?

Hi,


I am not getting any errors, my attempts at sorting simply returns same results every time whether I use asc/desc or different dimension names.


No idea how to page either

Userlevel 3
Badge

@emmett This might be silly but are you missing a $ in front of the sort object you’re trying to interpolate into that string?


... &sorts={sort}&limit=${limit} ...

oh good spot, that solved it 🙂


2 more questions if I may


1 what does the 0 mean in the . sort: sales_table.customer_first_name desc 0

2. is there any way I can get the total results back in the results so that i can subsequently page through them ?

Userlevel 3
Badge

I’m not actually sure. I tested it a bit on my end and adding/removing the 0 or 1 or whatever after the sort definition doesn’t really do anything. It didn’t change the query at all and it even used the same cache key, so I think that might just be a mistake.


thanks, got any advice on paging ?

Userlevel 3
Badge

I don’t think we support paging for API requests right now, but I can talk to our Product team about building in support for this. Maybe just a bool parameter?

I think we are going for an alternative approach now, but in general if you were to add paging you would need to accept ‘page’ and ‘max’ params e.g. page=2&max=10


so if 1000 results in whole pageable dataset then page=2&max=10 would retrieve results 10-19

Reply