开发者

Initializing GridPanel and ArrayStore with empty array does not work

开发者 https://www.devze.com 2023-01-12 09:49 出处:网络
When I initialize my ArrayStore with some data then I can insert new records and everything displays correctly. However, if I initialize the ArrayStore with an empty array then while the first record

When I initialize my ArrayStore with some data then I can insert new records and everything displays correctly. However, if I initialize the ArrayStore with an empty array then while the first record inserted works every subsequent insert overwrites the first record in the grid. This seems a simple problem but I can't find a working way to initialize the grid as empty.

So what am I doing wrong?

Many thanks in advance!

var myData = [
    // Initializing with the following element works.
    //['Hyannis Connector',3456.9,'Hyannis Connector Bridle Path','Hyannis Connector/Baden Powell'],
    // Initializing with this element works but l开发者_StackOverflow社区eaves an empty row in the grid..
    //[]
];

// create the data store
segmentStore = new Ext.data.ArrayStore({
    fields: [
       {name: 'trailName'},
       {name: 'segmentLength', type: 'float'},
       {name: 'startJunction'},
       {name: 'endJunction'},
    ]
});

// manually load local data
segmentStore.loadData(myData);

// create the Grid
segmentGrid = new Ext.grid.GridPanel({
    region: 'south',
    store: segmentStore,
    columns: [
        {header: 'Trail Name', width: 140, sortable: true, dataIndex: 'trailName'},
        {header: 'Segment Length', width: 75, sortable: true, dataIndex: 'segmentLength'},
        {header: 'Start Junction', width: 75, sortable: true, dataIndex: 'startJunction'},
        {header: 'End Junction', width: 75, sortable: true, dataIndex: 'endJunction'},            
    ],
    stripeRows: true,
    height: 150,
    width: 600,
    title: 'Trail Segments in Route',
    layout: 'fit'      
});

var defaultData = {
            trailName: segment.getTrailName(),
            segmentLength: segment.getLength(),
            startJunction: '',
            endJunction: ''
        };
        var recId = 3; 
        var p = new segmentStore.recordType(defaultData, recId); 
        segmentStore.insert(0, p);


The answer was provided in the ExtJS Forum. I needed to ensure the record id of the new records was different.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号