我使用的是Dojo Toolkit 1.9 Datagrid,我从xmlStore填充数据,但我面临的一个问题是,在从数据网格中删除任何项目后,在手动刷新浏览器之前,它不会得到刷新。有人能建议我怎么做吗?源代码如下:
<html>
<head>
<title>User Demo</title>
<link rel="stylesheet" href="../dojo-release-1.9.1/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="../dojo-release-1.9.1/dojox/grid/resources/claroGrid.css">
<script src='../dojo-release-1.9.1/dojo/dojo.js'></script>
<script src='myscript.js'></script>
<body>
<div id="ObjectGrid"></div>
</body>
</html>
var globalUserId;
var appContext = "/" + (window.location.pathname).split("/")[1];
require(
[ 'dojo/dom', 'dojo/json', 'dojox/json/schema',
'dojox/data/JsonRestStore', 'dojox/grid/DataGrid',
'dojox/grid/_CheckBoxSelector', 'dojo/on',
'dojo/request/xhr', 'dijit/Dialog', 'dojox/data/XmlStore',
'dijit/form/FilteringSelect', 'dijit/Calendar',
'dijit/form/Form', 'dijit/form/ValidationTextBox',
'dijit/form/TextBox', 'dijit/form/FilteringSelect',
'dijit/form/Button', 'dijit/layout/TabContainer',
'dijit/layout/ContentPane', 'dojo/domReady!' ],
function(dom, JSON, schema, JsonRestStore, DataGrid,
_CheckBoxSelector, on, xhr) {
var userDataStore12 = new dojox.data.XmlStore({
url : appContext + "/rest/userservice/getusers",
rootItem : "user"
});
var gridCell = [{field : "userid",name : "User Id",width : '10%'},
{field : "name",name : "Name",width : '15%'},
{field : "email",name : "Email",width : '15%'},
{field : "userName",name : "User Name",width : '10%'},
{field : "phone",name : "Phone",width : '10%'},
{field : "roleName",name : "Role",width : '10%'},
{field : "status",name : "Status",width : '10%'},
{name : "Action",field : "action",width : '10%',
formatter : function(item) {
var link = '<a href="#" title="Edit" onClick="updateUserDialog.show()"><div class="dijitIconEdit"></div></a> <a href="#" id="deleteUser" onClick="deleteUser();" title="Delete"><div class="dijitIconDelete"></div></a>';
return link;
}
}];
gridLayout = [ {
// First, our view using the _CheckBoxSelector custom type
type : "dojox.grid._CheckBoxSelector"
}, gridCell ];
grid = new DataGrid({
store : userDataStore12,
structure : gridLayout,
selectionMode : "single",
autoHeight : true
}, "ObjectGrid");
grid.startup();
on(grid, "RowClick", function showDetail(e) {
var gridUserId = grid.store.getValue(grid.getItem(e.rowIndex), "userid");
globalUserId = gridUserId;
});
});
function deleteUser() {
require([ 'dojo/dom', 'dojo/request' ], function(dom, request) {
//request for delete user
request.post(appContext + "/rest/userservice/deleteUser", {
data : "userId=" + globalUserId,
timeout : 2000
}).then(function(response) {
console.log("request sent successfully!!!!!!!");
});
});
}
我已经通过这种方式删除了Datagrid的一行。我通过复选框选择一行,然后通过网格末尾的按钮调用函数getSelectedItems()来删除所选行。
function getSelectedItems(){
require(["dijit/registry", "dojo/_base/array", "dojo/domReady!"], function(registry, array){
var items = registry.byId("GraphGrid").selection.getSelected();
if (items.length) {
array.forEach(items, function(selectedItem){
/* Delete the item from the data store: */
GraphicStore.deleteItem(selectedItem);
});
}
});
}
更新
时间有点晚了,我不确定这个问题是否仍然存在,但我现在为我解决了这个问题。我的问题和你的几乎一样。我在ContentPane中显示了一个数据网格,并希望删除单个行。问题是,在我删除项目后,网格没有刷新。所以我用重新加载
grid.setStore(GraphicStore);
但是,除了列标题之外,ContentPane仍然是空的。当我对行进行排序时,会出现新的网格。然后我设置了一个警报,看看网格是否仍然注册,有了这个警报,网格突然出现了!为了解决这个问题,我设置了一个超时,这样网格就可以完全加载(我想这与加载有关),并设置新的存储。Gird出现-问题解决了。
我是这样做的:
setTimeout(function(){
grid.setStore(GraphicStore);
}, 1000);
此致,Miriam