Charles Whitcombe
Posts: 0
Joined: Sun Nov 10, 2013 7:48 pm

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

Hi Max,
thanks but newish to this..

I've put javascript of

var count = data.allSaved.length;
console.log(count);
localStorage.setItem('total', count);

as event on query success, where allSaved is the name of the response parameter:

$allSaved
-userId
-name
etc..

but console gives warning of
Uncaught TypeError: Cannot read property 'length' of undefined

what is the correct syntax here? Thanks

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

Hi Charles, we have a tutorial that describes approach how to work with objects in the collection, it can help to understand :: http://docs.appery.io/tutorials/build...

Charles Whitcombe
Posts: 0
Joined: Sun Nov 10, 2013 7:48 pm

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

Hi Illya, thanks again, looked at that but how would I count the objects that I've already returned using a query service with 'where' and 'sort' parameters - needs to be dynamic as service will return different number of objects based on request?

Can I add a 'count' request parameter to the query like I've already added 'limit' and 'skip'? If so, how would I get the response from that?

Or could I use JS on success event as I've written above? I suspect this is the way but not sure of syntax and how to capture this..

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

Hi Charles,

You can add one more Request parameter "count" that returns a number of elements. You should do this in separate service and call separately. Or you can count mapped items manually:prevar myCount = localStorage.getItem("myCount");
localStorage.setItem("myCount",myCount++);/preAdd this code to an array item mapping.

Charles Whitcombe
Posts: 0
Joined: Sun Nov 10, 2013 7:48 pm

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

Thanks for your help - in the end I just put a show more button that skipped through the rows of filtered query objects.

ang .
Posts: 0
Joined: Thu Jan 09, 2014 3:13 am

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

I have created 2 service, one with paratmeter count = 0, another count = 1, but both service return count only, how can I have one service return array of database items, another specifically return number of rows only?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

Hi,

It's better to remove the code added before. Then on service Success event run this JavaScript code: prevar count = data.length;/preWhere 'count' is a number of response elements.

Another service will return data. If these services use the same parameters then you can add this code to one of them and call it.

Shawn
Posts: 0
Joined: Sat Jun 21, 2014 11:13 pm

For the 'total' local variable required for pagination, how do I acquire the number of returned objects from a query ser

If we have implemented pagination and added this code then doesnt this return the limit value and not the total records in query ?

Return to “Issues”