0

我正在使用 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!!!!!!!");

            });
        });

    }
4

1 回答 1

1

我已经设法以这种方式删除了 Datagrid 的单行。我通过复选框选择一行,然后通过 Grid 末尾的按钮调用函数 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 中的 Datagrid,并且想要删除单个行。问题是我删除该项目后,网格没有刷新。所以我重新加载它

grid.setStore(GraphicStore);

但是除了列标题之外,ContentPane 仍然是空的。当我对行进行排序时,会出现新的网格。然后我设置了一个警报,看看网格是否仍然注册,随着这个警报,网格突然出现了!为了解决这个问题,我设置了一个超时,因此可以完全加载网格(我猜它与加载有关)并设置新商店。出现网格 - 问题已解决。

我这样做:

  setTimeout(function(){
    grid.setStore(GraphicStore);
    }, 1000);

问候,米里亚姆

于 2013-08-26T07:49:53.443 回答