开发者

Dojo: dojox.grid.enhanced.plugins.Filter - all items are cleared from the grid on filtering

开发者 https://www.devze.com 2023-03-25 22:37 出处:网络
I\'ve got a dojox.grid.EnhancedGrid with a dojox.grid.enhanced.plugins.Filter and a dojo.store.Memory wrapped in a dojo.data.ObjectStore. Whenever I try to filter, all records are removed from the gri

I've got a dojox.grid.EnhancedGrid with a dojox.grid.enhanced.plugins.Filter and a dojo.store.Memory wrapped in a dojo.data.ObjectStore. Whenever I try to filter, all records are removed from the grid. I get a '0 of 0 items sh开发者_如何学JAVAown' message. When i click 'clear filter' the grid remains empty.

Update: The plot thickens. It seems that just sorting the grid by a column clears the grid. I'm trying to get a basic example working here: http://jsfiddle.net/wp64T/4/


I had the same problem and only managed to fix it by running the grid filter periodically in the background with the help of some jQuery. Here is some sample code; hope this helps someone else having problems with this.

// ADD JQUERY
<script src="http://code.jquery.com/jquery-latest.js"></script>

.

// PUT THIS IN THE <HEAD> OF THE PAGE
<script type="text/javascript">
    $(document).ready(function() {
        function filterTheDataGrid() {
            if (dijit.byId("grid") != undefined) {
                dijit.byId("grid").filter({color: "Red"});
            }
        }
    // RUN THE filterTheDataGrid FUNCTION EVERY ONE SECOND (1000 MILLISECONDS) //
    // LOWER '1000' FOR FASTER REFRESHING, MAYBE TO 500 FOR EVERY 0.5 SECOND REFRESHES //
    var refreshDataGrid = setInterval(function() {  filterTheDataGrid();    }, 1000);
    }
</script>

.

// PUT THIS IN THE <HEAD> OF THE PAGE
<script type="text/javascript">
    // SETUP THE LAYOUT FOR THE DATA //
    var layoutItems = [[
    {
        field: "id",
        name: "ID",
        width: '5px',
        hidden: true
    },
    {
        field: "color",
        name: "Color",
        width: '80px'
    }
]];

// Create an empty datastore //
var storeData = {
    identifier: 'id',
    label: 'id',
    items: []
}
var store3 = new dojo.data.ItemFileWriteStore( {data : storeData} );
</script>

.

 // PUT THIS IN THE <HTML> OF THE PAGE
<div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutItems" query="{ type: '*' }" clientSort="true" rowsPerPage="40"></div>

.

<script type="text/javascript">
function addItemToGrid(formdata) {
    // THIS FUNCTION IS CALLED BY A DIALOG BOX AND GETS FORM DATA PASSED TO IT //
    var jsonobj = eval("(" + dojo.toJson(formData, true) + ")");

    var myNewItem = {
        id: transactionItemID,
        color: jsonobj.color
    };
    // Insert the new item into the store:
    store3.newItem(myNewItem);
    store3.save({onComplete: savecomplete, onError: saveerror});
}
</script>


Can you please provide a code snippet or jsFiddle? Without it the best guess I can provide is you are attempting to filter on a store value that does not exist, and your clear filter button only modifies the textbox and does not re-fire the filter command to reset it.

Edit :

Please try http://download.dojotoolkit.org/release-1.4.0/dojo-release-1.4.0/dojox/grid/tests/test_data_grid.html

Three console commands :

dijit.byId("grid").filter({name : "A*"}) Will give all that start with A.

dijit.byId("grid").filter({name : "*"}) Will give the original result set back(all).

dijit.byId("grid").filter({name : ""}) Will clear the grid, nothing matches.

I realize this isn't quite the API you are using(dojo.data.ObjectStore) but it should follow the same logic. My guess is you ended up trying to filter against "" and matched nothing, resulting in your zero element grid. Don' forget the asterisk if you are looking to do begins-width/contains/ends-width.

0

精彩评论

暂无评论...
验证码 换一张
取 消