Question

I add new rows(records) in to the grid when load store event as bellow

var dt = new Date();
var rec = new store.recordType({ }, "new" + dt.format('U'));
rec.set('ID', '1');
store.insert(store.getCount(), rec);
store.insert(store.getCount()+1, rec);
grid.getView().refresh();

but i can't add 2 empty last rows in to the grid. how can i add 2 empty row in to the grid.

Note: without this line only add one row in to the grid store.insert(store.getCount()+1, rec); but when i add store.insert(store.getCount()+1, rec); in to my code that gave to me error.

Was it helpful?

Solution

First some comment concerning your code snipped:

You are creating a new record with the ID value "new" + dt.format('U') and in the next line you are setting this ID to 1? You should create the record with the appropriate (and unique) ID. Otherwise you may override a existing record.

Now your problem:

You are adding a record with the same ID twice. So for the store there is only one record. Either don't assign a ID value at all and let ExtJS take care of it or ensure that each instance get it's own unique ID. And create a new instance each time!

You need to do something like this:

var rec1 = new store.recordType({}, 1); // remove the 1 with your own unique ID value
var rec2 = new store.recordType({}, 2); // remove the 2 with your own unique ID value

store.insert(store.getCount()-1, [rec1,rec2]);

OTHER TIPS

I've done something like this for combos (but not with empty values) and worked just fine ... hope it works for you ...

Given a model with this 2 properties FullName Age

When you load the store ...

someStore.load({

callback:function(){

 someStore.add(

   {FullName: '', Age:''}, {FullName: '', Age:''}

)

}

});

Note that if this Store is sorted, the new Model instances will be inserted at the correct point in the Store to maintain the sort order.

Available since: 1.1.0

http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add

Best regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top