使用JsonRest Store向ondemandgrid样式的dGrid添加实时查询

Adding a Live Query to an OnDemandGrid-style dGrid Using a JsonRest Store?

本文关键字:dGrid 添加 实时 查询 样式 JsonRest Store ondemandgrid 使用      更新时间:2023-09-26

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

我在dGrid文档中找不到任何例子,虽然这看起来只是事情-是否有可能在dGrid中过滤数据,就像在数据网格中一样?如果有,怎么做?-它使用MemoryStore并将其交换为JsonRest存储不起作用。

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

大概也需要在服务器上做一些改变来响应查询。

事实证明这相当容易。您只需在网格上设置查询属性并调用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 );
    } );
} );