2013-06-20 5 views
0

나는 extjs4에서 일하고있다. 코드가있는 항목으로 표가있는보기 :extjs4에서 삭제시 그리드에서 레코드를 삭제하는 방법

{ 
      margin : '10 0 5 100', 
      xtype : 'grid', 
      id : 'g3', 
      //title : 'Educational Details', 
      store:'qb.qbquestionoptionStore', 
      columns : [ { 
       text : 'questionId', 
       dataIndex : 'questionId', 
       flex : 1 
      }, 

      { 
       text : 'category', 
       dataIndex : 'category', 
       flex : 1 
      }, { 
       text : 'Answer', 
       dataIndex : 'isAnswer', 
       flex : 2.5 
      }, 
      { 
       header : 'Remove', 
       renderer : function(val) { 
        return '<a href="#" id="remove">Remove</a>'; 
       }, 
      } 

따라서 링크를 클릭하면 해당 항목이 데이터베이스에서 삭제됩니다. 그러나 그리드는 여전히 삭제 된 항목을 보여줍니다. 컨트롤러에서 나는 그것을위한 코드가있다.

deleterow:function(cmp) 
      { 
       cmp.mon(cmp.getEl(),'click',function(event,target) 
         { 
        if(target.id=='remove') 
        { 
        // alert("hello"); 

         listview=Ext.getCmp('g3'); 

         listview.on({ 
          itemClick: function(dv, record, item, index, e,opts) 
          { 
           liststore=this.getStore('qb.qbquestioncomplexityStore').sync(); 
           liststore.load({ 
            params:{ 
             id:record.data.id, 
             questionId:record.data.questionId 

            } 
           }); 
           console.log(record); 
           console.log(" Id is "+record.data.id); 
         var shopCart=Ext.create('Balaee.model.qb.qbquestioncomplexityModel', 
             { 
            id:record.data.id, 
            questionId:record.data.questionId 
             }); 
           Ext.Msg.confirm('Confirm to delete', 'Want to delete record?', function (button) 
             { 
            if (button == 'yes') 
            { 
            shopCart.destroy(); 

            } 
             }); } 
         }); } 
      },this,{delegate:"a"}); 

      }, 

그리드에서 레코드를 삭제하는 방법.

답변

1

코드는 조금 이상한하지만 난 당신이 거의 있다고 생각 : 당신이 모델에 대한 프록시를 설정 한 경우

가장 쉬운 방법입니다. destroy()으로 전화하면됩니다. 이 레코드가 바인드 된 모든 상점에 통지됩니다. 나는 당신의 레코드가 하나 개의 저장소에 바인딩되는이 예를 들어 가정 할 경우

if (button == 'yes'){ 
    record.destroy(); 
    shopCart.destroy(); 
} 

, 다음 gridpanel에서 행을 제거하는

if (button == 'yes'){ 
    var s = record.store; 
    s.remove(record); 
    s.store.sync(); 
    shopCart.destroy(); 
} 
+0

고맙습니다 ... 내가 사용하는 경우 "record.store.remove (기록) record.store.sync(); shopCart.destroy를();" 그게 나에게 오류를 준다 Uncaught TypeError : null의 'sync'메서드를 호출 할 수 없다 – user1722857

+0

@ user1722857 죄송합니다. 내 잘못입니다. 나는 내 대답을 편집했다. – sra

+0

고맙습니다 답장을드립니다 .... 나는 당신이 제안한대로 다음과 같습니다. 하지만 이제는 오류가 발생했습니다. "Uncaught Ext.data.proxy.Server.buildUrl() : ServerProxy를 사용하고 있지만 URL을 제공하지 않았습니다." 모델의 프록시를 사용하고 있습니다. 그래서 내가해야 할 변화 – user1722857

2

처럼 할 수있는, 내가 같은 것을 할 : 도움을

var selectedRecord = grid.getSelectionModel().getSelection()[0]; 
grid.getStore().each(function(rec) { 
    if (rec == selectedRecord) { 
     grid.store.remove(rec); 
    } 
}); 
grid.getView().refresh();