Ticket #5843: dojox.data.QueryReadStore.patch

File dojox.data.QueryReadStore.patch, 3.8 kB (added by jaredj, 10 months ago)

Patch to do passthrough to server for proper sorting and paging.

  • data/QueryReadStore.js

     
    7575        // does not do the paging. 
    7676        doClientPaging:true, 
    7777 
     78        // If this is false, all the sorting is done serverside before the data is returned 
     79        // which is the proper place to be doing it for really large datasets. 
     80        doClientSorting:true, 
     81 
    7882        // Items by identify for Identify API 
    7983        _itemsByIdentity:null, 
    8084         
     
    225229                        if(requestObject.onBegin){ 
    226230                                requestObject.onBegin.call(scope, numRows, requestObject); 
    227231                        } 
    228                         if(requestObject.sort){ 
     232                        if(requestObject.sort && this.doClientSorting){ 
    229233                                items.sort(dojo.data.util.sorter.createSortFunction(requestObject.sort, self)); 
    230234                        } 
    231235                        if(requestObject.onItem){ 
     
    312316                                serverQuery.count = request.count; 
    313317                        } 
    314318                } 
     319                if(!this.doClientSorting){ 
     320                        if(request.sort){ 
     321                                var sort = request.sort[0]; 
     322                                if(sort && sort.attribute){ 
     323                                        var sortStr = sort.attribute; 
     324                                        if(sort.descending){ 
     325                                                sortStr = "-" + sortStr; 
     326                                        } 
     327                                        serverQuery.sort = sortStr; 
     328                                } 
     329                        } 
     330                } 
    315331                // Compare the last query and the current query by simply json-encoding them, 
    316332                // so we dont have to do any deep object compare ... is there some dojo.areObjectsEqual()??? 
    317333                if(this.doClientPaging && this._lastServerQuery!==null && 
  • data/tests/QueryReadStore_grid.html

     
     1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
     2                "http://www.w3.org/TR/html4/strict.dtd"> 
     3<html> 
     4<head> 
     5        <style type="text/css"> 
     6                @import "../../../dojo/resources/dojo.css"; 
     7                @import "../../../dijit/themes/tundra/tundra.css"; 
     8                @import "../../../dijit/themes/tundra/tundra_rtl.css"; 
     9                @import "../../grid/_grid/tundraGrid.css"; 
     10                @import "../../../dijit/tests/css/dijitTests.css"; 
     11        </style> 
     12 
     13        <title>Query read store test with grid and serverside sorting/paging</title> 
     14 
     15        <script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script> 
     16        <script type="text/javascript"> 
     17                dojo.require("dojox.data.QueryReadStore"); 
     18                dojo.require("dojox.grid.Grid"); 
     19                dojo.require("dojo.parser"); 
     20        </script> 
     21    <script type="text/javascript"> 
     22                var layoutStates = [ 
     23                        { cells: [[ 
     24                                { field: "label", name: "Label", width: '20' }, 
     25                                { field: "abbreviation", name: "Abbreviation", width: 20 } 
     26                        ]]} 
     27                ]; 
     28        </script>        
     29</head> 
     30<body class="tundra"> 
     31    <p> 
     32        This simple demo shows the use of QueryReadStore talking to a simple PHP server script that can handle 
     33        serverside paging and sorting.  This demonstrates that virtual scrolling and sorting can work properly 
     34        with server based data stores. 
     35    </p> 
     36 
     37    <!-- Construct QueryReadStore impl that defines that the server should do all sorting and paging 
     38         The reasonable way to handle grid.   
     39    --> 
     40        <div dojoType="dojox.data.QueryReadStore"  
     41         jsId="queryStore"  
     42         url="stores/QueryReadStore.php"  
     43         requestMethod="get"  
     44         doClientPaging="false"  
     45         doClientSorting="false"></div> 
     46  
     47    <div dojoType="dojox.grid.data.DojoData"  
     48         jsId="queryModel"    
     49         store="queryStore"  
     50         query="{label: '*'}"  
     51         sortFields="[{attribute: 'name', descending: true}]"  
     52         rowsPerPage="5"> 
     53    </div> 
     54    <div dojoType="dojox.grid.Grid"  
     55         style="width: 500px; height: 200px;"  
     56         model="queryModel",  
     57         structure="layoutStates"></div> 
     58</body> 
     59</html>