2013-08-26 4 views
0

Dojo Toolkit 1.9 Datagrid를 사용하고 있는데 xmlStore에서 데이터를 채우고 있지만 데이터 그릿에서 항목을 삭제 한 후 우리는 수동 브라우저를 새로 고칩니다. 당신이 나에게 어떻게 제안 할 수 있겠 니? 소스 코드는 다음과 같습니다 : 나는 데이터 그리드의 단일 행이 방법으로 삭제 처리했다항목을 삭제 한 후 dojo 1.9에서 DataGrid를 새로 고치는 방법

<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!!!!!!!"); 

      }); 
     }); 

    } 
+0

내 대답을 업데이트 :

나는 이런 식으로 할 – MiBrock

답변

1

. 나는 체크 박스를 통해 행을 선택한 다음, 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); 
     }); 
    } 
    }); 
} 

업데이트

는 조금 나중에이고 나는이 문제는 여전히 실제입니다 확실하지 않다 그러나 나는 지금 나를 위해이 문제를 해결한다. 내 문제는 당신과 거의 같았습니다. Datagrid를 ContentPane에 표시하고 단일 행을 삭제하려고합니다. 문제는 내가 항목을 삭제 한 후 그리드가 새로 고쳐지지 않았기 때문입니다. 그래서 내가 다시로드

그러나 ContentPane은 열 머리글을 제외하고는 빈 채로 남아 있습니다. 내가 행을 정렬하면 새 Grid가 나타납니다. 그런 다음 그리드가 아직 등록되어 있지 않은지 알기 위해 경고를 설정하고이 경고로 그리드가 갑자기 나타납니다! 이 문제를 해결하려면 시간 제한을 설정하십시오. 그리드가 완전히로드 될 수 있습니다 (로드와 관련이있는 것 같음). 새 저장소를 설정합니다. 새가 나타납니다 - 문제가 해결되었습니다.

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

감사합니다, 미리 암

관련 문제