Extjs Grid - Delete all record has a conditional -


i have grid , button delete in http://jsfiddle.net/9zb8r/
field fields: ['id', 'name', 'type']. if type == delete delete it.
init data like:

var simpledata = [];     var store = new ext.data.arraystore({         fields: ['id', 'name', 'type'],         data: simpledata     });     (i = 0; < 20; i++) {         simpledata.push({id:''+i+'', name: 'name'+i, type: 'delete'});         }     //this record not delete     simpledata.push({id:'20', name: 'enable', type: 'enable'});          store.loaddata(simpledata); 

i have tbar below can't delete record have type == delete. how can fix that. thanks.

tbar:[         {                 text:'delete type = delete',             handler:function(){                 store.each(function(item, idx) {                     if (item && item.get('type')=='delete') {                         store.removeat(idx);                        }                 });             }         }         ] 

the problem "each" loop. removing items in loop changing store size , hence of items getting deleted.

to around it, can loop through store in reverse order , delete below:

var grid = new ext.grid.gridpanel({     width: 400,     height: 600,     store: store,     loadmask: true,     renderto: ext.getbody(),     tbar:[     {             text:'delete type = delete',         handler:function(){             var = store.getcount()-1;              (i; i>=0; i--) {                 if (store.getat(i).get('type')=='delete') {                     store.removeat(i);                 }             }          }     }     ], 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -