Changing Sort Direction

25 views
Skip to first unread message

Todd Freese

unread,
Mar 4, 2014, 4:11:32 PM3/4/14
to mobile-c...@googlegroups.com
I can't seem to change the direction of the sorting. 

Here is my view code:

[view setMapBlock: MAPBLOCK({

     if ([doc[@"type"] isEqualToString:kJobDocType]) {

        NSString *value = ([NSString stringWithFormat:@"%@ %@ %@ %@ %@", doc[@"jobNumber"], doc[@"workingTitle"], doc[@"clientName"], doc[@"product"], doc[@"productionCompany"]]);

        emit(doc[@"created_at"], value);

     }

 }) reduceBlock:nil version: @"1"];


Any my query code:


self.dataSource.query.descending = YES;

self.dataSource.query = [Job queryJobsInDatabase:database].asLiveQuery;


Changing self.dataSource.query.descending between YES and NO seems to have no effect. (I am using CBLTableSource here.)


Is there something I am missing?


Todd

Jens Alfke

unread,
Mar 4, 2014, 4:43:40 PM3/4/14
to mobile-c...@googlegroups.com

On Mar 4, 2014, at 1:11 PM, Todd Freese <to...@filmworkers.com> wrote:

> self.dataSource.query.descending = YES;
> self.dataSource.query = [Job queryJobsInDatabase:database].asLiveQuery;

If the statements really are in that order, I’m not surprised the first one has no effect ;-)

Actually, even if you swap the lines, it’s not going to work. Setting the dataSource’s query property will make it start running the query, and after that happens it’s too late to change the options. The right way to set it up is something like
CBLLiveQuery* query = [view createQuery].asLiveQuery;
query.descending = YES;
self.dataSource.query = query;

—Jens

Todd Freese

unread,
Mar 4, 2014, 4:59:28 PM3/4/14
to mobile-c...@googlegroups.com
D'oh! Of course, these need to be set before assigning the query.

Todd
Reply all
Reply to author
Forward
0 new messages