使用JsonRest存储将实时查询添加到OnDemandGrid样式的dGrid?

时间:2013-01-11 14:29:23

标签: javascript dojo dgrid

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

我在dGrid文档中找不到任何示例,虽然这看起来只是事情 - Is it possible to filter data in a dgrid like you can in a datagrid? If so, how? - 它使用MemoryStore并将其交换为JsonRest存储不起作用。

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

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

1 个答案:

答案 0 :(得分:0)

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

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

这是我的代码:

// 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 );
    } );
} );