开发者

Adding a filtering constraint programmatically to a Dojo Enhanced Grid

I added the filtering plugin to my Dojox Enhanced Grid开发者_开发知识库. Now I would like to create my own constraint that filters the grid without user input. The normal grid.filter is deactivated if I use the filtering plugin.

Do subclasses like dojox.grid.enhanced.plugins.filter.BooleanExpr offer that functionality and what would the syntax for a simple filter (by ID for example) look like?


I had a similar problem and only managed to fix it by running the grid filter periodically in the background with the help of some jQuery. I believe this same method may work for what you're trying to do. Here is some sample code:

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 filterTheDataGrid every 1000 milliseconds //
    // Lower 1000 for faster refreshing, maybe to 500 milliseconds //
    var refreshDataGrid = setInterval(function() { filterTheDataGrid(); }, 1000);
    }
</script>

and this:

<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>

and this:

<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>

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜