如何重新过滤dojo DataGrid



我已经使用grid过滤了一个DataGrid。rerender过滤器(查询)。如果我添加另一个项目,在调用save()之后,我将在网格中看到新项目,尽管由于过滤器的原因它不应该显示。我在想:"好吧,等商店保存完,我再过滤一下。"但是打过电话之后。用相同的查询过滤所有的行消失。知道我哪里做错了吗?

筛选网格的代码:

var filterQuery = dijit.byId("filterTextbox").attr("value");
var grid = dijit.byId("grid");
var queryValue = "*";
if(filterQuery != ""){
    queryValue += filterQuery + "*";
}
grid.filter({name: queryValue}, true);

向网格中添加新项的代码

function addItemToGrid(newItemName){
     var newItem = {name: newItemName};
     var grid = dijit.byId("grid");
     var store = grid.store;
     store.addItem(newItem);
     store.save();
}

尝试使用:

store.newItem(newItem);

代替store.addItem(newItem);(addItem不是一个标准的方法来添加项目到存储)

在你的addItemToGrid函数中,尝试在你的保存方法中添加一个onComplete监听器,并在onComplete函数中对网格进行排序或过滤

store.save({onComplete: function() {
         grid.filter({name: queryValue}, true);
    }
});

我也遇到了同样的问题,只有在jQuery的帮助下,在后台定期运行网格过滤器才能解决这个问题。下面是一些示例代码;

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

相关内容

  • 没有找到相关文章

最新更新