Opened 8 years ago

Closed 7 years ago

#14756 closed defect (patchwelcome)

EnhancedGrid with JsonRestQueryStore fetches additional pages

Reported by: sudhas Owned by: Evan
Priority: undecided Milestone: tbd
Component: DojoX Grid Version: 1.7.1
Keywords: Cc:
Blocked By: Blocking:

Description

When using pagination with a combination of cookie-plugin-enabled + nestedSorted-enabled + sortFields set in a grid based on JsonQueryRestStore?, a reload of the page triggers a fetch of the second page.

The test html below is a simplified version of the pagination test in dojo with a few grid plugins enabled and sortFields set on the grid:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
<html dir="ltr">
<head>
        <title>Test Pagination plugin of dojox.grid.EnhancedGrid</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
        <style someProperty="text/css">
                @import "dojo/dojo/resources/dojo.css";
                @import "dojo/dijit/themes/claro/claro.css";
                @import "dojo/dojox/grid/resources/Grid.css";
                @import "dojo/dojox/grid/resources/claroGrid.css";
                @import "dojo/dojox/grid/enhanced/resources/claro/EnhancedGrid.css";
        </style>


        <script type="text/javascript" src="dojo/dojo/dojo.js" djConfig="isDebug:false, debugAtAllCosts: true, parseOnLoad: true"></script>
        <script type="text/javascript">
                dojo.require("dojox.data.JsonQueryRestStore");
                dojo.require("dojox.grid.EnhancedGrid");
                dojo.require("dojox.grid.enhanced.plugins.Pagination");
                dojo.require("dojo.parser");

                var layout = [{
                        cells: [
                                { field: "id", name:"Index", datatype:"number", width: 4},
                                { field: "data", name:"Data", datatype:"string", width: 10}
                        ]
                }];
                var plugins = {
                        nestedSorting: true,
                        cookie: true,
                        pagination: {
                                pageSizes: ["10", "25", "30", "50", "100"],// Array, custom the items per page button
                                position: "top" // String, custom the position of the pagination bar. There're two options: top, bottom
                        }
                };

                jqueryreststore = new dojox.data.JsonQueryRestStore({target:"test.php&restargs="});
                var grid;
                dojo.ready(function(){
                        grid = dijit.byId("grid");
                });

        </script>
</head>
<body class="claro">
<br/>
<h1>EnhancedGrid with pagination + JsonQueryRestStore</h1>
        <div id="gridContainer" style="height: 900px; width: 500px;">
                <div id="grid" sortFields="[{attribute: 'data', descending: true}]"
dojoType="dojox.grid.EnhancedGrid" store="jqueryreststore" structure="layout" plugins="plugins"></div>
        </div><br/>
</body>
</html>

The underlying php code that simply creates dummy data is:

<?php

function parseArgs($args, &$range) {
        if (preg_match("/\[:(.*)]$/", $args, $matches)) {
                $range[0] = 0;
                $range[1] = intval($matches[1]);
        } else {
                $tmp = preg_split("/:|\[|\]/", $args);
                $range[0] = intval($tmp[count($tmp)-3]);
                $range[1] = intval($tmp[count($tmp)-2]);
        }
}

if (array_key_exists("restargs", $_GET))
        $restargs = $_GET["restargs"];
if (preg_match('/^\/(.*)$/', $restargs, $matches)) {
        $restargs = $matches[1];
}

if ($restargs !== "") {
        parseArgs($restargs, $range);
}

$hdrtxt = 'Content-Range: items ' . $range[0] . '-' . ($range[1]-1) . '/1000';
header($hdrtxt);
header('Content-type: text/html');

echo "[";
$printstarted = false;
for ($i = $range[0]; $i < $range[1]; $i++)
{
        if ($printstarted)
                echo ",";
        else
                $printstarted = true;
        echo "{id: \"" . $i . "\", data: \"Data " . $i . "\"}";
}
echo "]";

?>

The first time that the page is loaded, the requested range is 0-24. When the page is refreshed, initially the first page is fetched and shown, followed by a fetch and display of the second page. In some cases where the data is huge, say with more columns, a lot more consecutive pages are getting fetched and displayed one after another.

Attachments (1)

grid-plugin-bug.html (5.0 KB) - added by Florian 8 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 8 years ago by sudhas

Note that even though the second page is fetched and the display in pagination bar shows 26-50 items, the highlighted page in the pagination bar still stays as '1' even though it is really the second page which is being shown.

comment:2 Changed 8 years ago by sudhas

Adding the following options to the grid resolves the additional fetch, but leaves the pagination bar empty and seems to virtually populate the entire data-set so that when the grid is scrolled down, data is fetched in batches. Running grid._refresh() from the firebug console re-fetches the data and populates the pagination bar correctly.

autoHeight="25" rowsPerPage="25"

Changed 8 years ago by Florian

Attachment: grid-plugin-bug.html added

comment:3 Changed 8 years ago by Florian

I just found this ticket after hitting the same bug (and already created a testcase that I already attached a few seconds ago): As the 3 plugins are critical to my application I'd like the priority of this ticket to be raised.

Thanks and regards,

Florian

/edit: to show the bug open the grid-plugin-bug.html, reload it and watch the description (showing 6-10 of 30 elements) and the current-page (showing page 1)

Last edited 8 years ago by Florian (previous) (diff)

comment:4 Changed 8 years ago by Florian

Workaround: To disable cookie-storing of nested-sort-order (which seems to be the cause of this problem) simply add following lines to your page:

dojox.grid.enhanced.plugins.NestedSorting.prototype._loadNestedSortingProps = function(sortInfo, grid){
	return;
};

comment:5 Changed 7 years ago by bill

DojoX Grid and EnhancedGrid are deprecated in favor of dgrid and gridx.

You should upgrade your code to use one of those two grids.

We will consider patches to the old DojoX Grid code though.

comment:6 Changed 7 years ago by bill

Resolution: patchwelcome
Status: newclosed
Note: See TracTickets for help on using tickets.