0

当 dGrid 由 JsonRest 存储支持时,如何实现 dijit/TextBox 过滤 OnDemandGrid 样式 dGrid 中的数据?我想在框中搜索并在我输入时更新网格。

我在 dGrid 文档中找不到任何示例,尽管这看起来就是这样 -是否可以像在数据网格中一样过滤 dgrid 中的数据?如果是这样,怎么做?- 它使用 MemoryStore 并将其换成 JsonRest 存储不起作用。

我需要查询商店然后刷新网格吗?我需要 Observable 吗?dojo.store.util.SimpleQueryEngine 呢?这是答案的一部分。

据推测,服务器上也必须进行一些更改才能响应查询。

4

1 回答 1

0

事实证明这很容易。您只需在网格上设置查询属性并调用 refresh()。

然后我必须对我的服务器端代码进行简单的更改来处理 ?search=whatever 查询字符串。

这是我的代码:

// assuming we have a declarative dijit/TextBox and a reference to our grid in myGrid                                           
// wait for DOM before wiring up our textbox (when dijit parsed)
ready( function() 
{
    var timeoutId = null,
        searchTextBox = registry.byId( 'searchTextBox' );

    searchTextBox.watch( 'value', function( name, oldValue, newValue ) 
    {
        if( newValue.length == 1 )
        {
            return;
        }   

        if( timeoutId ) 
        {
            clearTimeout( timeoutId );
            timeoutId = null;
        };

        timeoutId = setTimeout( function() 
        {
            myGrid.query = { search: newValue };
            myGrid.refresh();
        }, 300 );
    } );
} );
于 2013-01-11T18:51:53.530 回答