Page 1 of 2

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

Posted: Sun Nov 10, 2013 7:48 pm
by Charles Whitcombe

Thanks in advance.


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

Posted: Sun Nov 10, 2013 7:49 pm
by maxkatz

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

Posted: Sun Nov 10, 2013 8:00 pm
by Charles Whitcombe

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


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

Posted: Sun Nov 10, 2013 11:06 pm
by Illya Stepanov

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...


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

Posted: Mon Nov 11, 2013 2:30 pm
by Charles Whitcombe

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..


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

Posted: Mon Nov 11, 2013 3:49 pm
by Kateryna Grynko

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.


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

Posted: Mon Nov 11, 2013 6:50 pm
by Charles Whitcombe

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


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

Posted: Fri Jan 24, 2014 5:51 am
by ang .

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?


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

Posted: Fri Jan 24, 2014 10:10 am
by Kateryna Grynko

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.


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

Posted: Wed Sep 10, 2014 8:31 pm
by Shawn

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