Opened 8 years ago

Closed 4 years ago

#13953 closed defect (wontfix)

dojo.store.util.QueryResults bug?

Reported by: rmaccracken Owned by: Kris Zyp
Priority: high Milestone: 1.11
Component: Data Version: 1.6.1
Keywords: Cc:
Blocked By: Blocking:

Description

I'm using the new dojo.store api for the first time and trying to create a store that does a single request to the server and fills up a dojo.store.Memory with the response. From then on it just works like a regular memory store. This is used to feed a dijit.form.FilteringSelect? with a page size of 20. I wrap the store using dojo.data.ObjectStore?.

So the first time the "query" function is called, I return the following:

    return dojo.store.util.QueryResults(deferred);

In dojo.store.util.QueryResults?, it then has the following code that gets run when a deferred is passed to it:

    results.total = dojo.when(results, function(results){
        return results.length;
    });

When the deferred is resolved with the final results, results.length is equal to the page size of 20 after the query is processed. However, I have also set results.total to be the true total of all the items now in the store - say 240. So what happens in this case is that deferred.total is set to 20 rather than 240.

This causes a problem downstream in dojo.data.ObjectStore? where there is the following code (the outermost "results" is referring to the deferred):

    dojo.when(results.total, function(totalCount){
        dojo.when(results, function(results){
            if(args.onBegin){
                args.onBegin.call(scope, totalCount || results.length, args);
            }

So onBegin is then called with a value of 20 rather than 240, and thus the FilteringSelect? does not show the Previous/More? choices options.

So here is my question: should the code above be changed to the following?

    results.total = dojo.when(results, function(results){
        return results.total || results.length;
    }); 

You can reproduce the problem at http://jsfiddle.net/vcKdF/1650/. Just press on the drop-down arrow and you will see 20 results with no option for "More choices", even though there are 25 options in all.

If you type "opt" in the select control, then you will get 20 options with the "More choices" option. So once the initial deferred is resolved, it works as expected.

Change History (3)

comment:1 Changed 8 years ago by Kris Zyp

The results.total assignment only happens if results.total is not there. Is there any reason you can't assign a "total" property with a deferred value that resolves to the total number of items (240) in your query method?

comment:2 in reply to:  1 Changed 8 years ago by rmaccracken

I guess I didn't think of it that way, but that could be done. I just assumed that results.total needed to be a number, but now that you mention it, I guess it could be another Deferred. This seems a bit more complicated though having to track multiple Deferreds.

I still think my initial fix is valid though since the result of dojo.query is supposed to have a "total" property. So when results is an array rather than a Deferred, results.length is not necessarily the appropriate total count.

comment:3 Changed 4 years ago by dylan

Milestone: tbd1.11
Resolution: wontfix
Status: newclosed

I think a number of patterns have emerged around this that are widely accepted now, so closing this as wont fix.

Note: See TracTickets for help on using tickets.