2012-10-12 73 views
0

我有我的enchancegrid名爲unitsGrid這是正常工作。我可以添加行和刪除行,但是當我刪除行時,我得到一些問題,我無法弄清楚,所以行刪除時不會從我的unitsGrid中消失。我一直在看代碼幾個小時,但我似乎無法弄清楚。 在此先感謝。dojox.grid.enchancegrid刪除行,從服務器行刪除但不是從網格

dojo.connect(unitsGrid, "onRowClick", unitsGrid, function(evt, rowIndx, fieldIndx){ 

      var idx = evt.rowIndex; 
      var item = this.getItem(idx); 
      var id = unitsGrid.store.getValue(item, "id"); 

      if(evt.cellIndex == 3) { 
       var con = confirm("Är du säker på att du vill radera denna transaktion?"); 
       if(con == true) { 
        dojo.xhrPost({ 
         url: url, 
         content: { 
          id: id 
         }, 
         handleAs: "text", 
         load: function(data) { 
          var selectedRows = grid.selection.getSelected(); 
          if (selectedRows.length) { 
          // Iterate through the list of selected items. 
          // The current item is available in the variable 
          // "selectedItem" within the following function: 
           dojo.forEach(selectedRows, function(selectedItem) { 
            if (selectedItem !== null) { 
             // Delete the item from the data store: 
             try { 
              unitsGrid.store.deleteItem(selectedItem); 
             } 
             catch(error) { 
              console.log("Returned error: " + error.message); 
             } 
            } // end if 
           }); // end forEach 
          } // end if 
          console.log("Return value: " + data); 
         }, 
         error: function(error) { 
          console.log(error); 
         } 
        }); // end xhrPost 
       } 
      } 

     }); 

回答

1

只需調用dijit.byId('unitsGrid')。removeSelectedRows();