简体   繁体   中英

ExtJS4 Grid store/model showing empty row(s)

My problem is very similar to this question:

ExtJS4 gridPanel data not showing

but in a bit difference in syntax & behaviour, I've spent day(s) to solve by trying in many ways but failed.

Please note that : i must keep the SharpKit.NET generation behavior by calling parent constructor instead of json field construction, like the code bellow

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    fields: ["title", "pages"] // Do not use this
});

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    constructor: function () {
        this.callParent([{ fields: ["title", "pages"] }]); // Use this
    }
});

This is link to my simplified version on jsfiddle http://jsfiddle.net/thanhptr/LqXan/ . Bellow is my copied code, this code still does not fix:

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    constructor: function () {
        this.callParent([{ fields: ["title", "pages"] }]);
    }
});
Ext.define("Core.Scripts.store.Store", {
    extend: "Ext.data.Store",
    constructor: function () {
        this.callParent([{
            model: "Core.Scripts.model.Book",
            data: [
                { title: "book 1", pages: 10 },
                { title: "book 2", pages: 20 }
            ]
        }]);
    }
});
Ext.define("Core.Scripts.view.GridPanel", {
    extend: "Ext.grid.Panel",
    constructor: function () {
        this.callParent([{
            store: new Core.Scripts.store.Store(),
            region: "center",
            columns: [
                { header: "title", dataIndex: "title" },
                { header: "pages", dataIndex: "pages" }
            ]
        }]);
    }
});
Ext.define("Core.Scripts.view.DetailViewport", {
    extend: "Ext.container.Viewport",
    constructor: function () {
        this.callParent([{
            frame: true,
            layout: "border",
            items: [new Core.Scripts.view.GridPanel()]
        }]);
    }
});
Ext.onReady(function () {
    var viewPort = new Core.Scripts.view.DetailViewport();
});

I couldn't get your example working either, but I changed some code up and got it to work.

Ext.define("Core.Scripts.model.Book", {
    extend: "Ext.data.Model",
    fields: ["title", "pages"]
});
Ext.define("Core.Scripts.store.Store", {
    extend: "Ext.data.Store",
    model: "Core.Scripts.model.Book",
    data: [
        { title: "book 1", pages: 10 },
        { title: "book 2", pages: 20 }
    ]
});

Ext.define("Core.Scripts.view.GridPanel", {
    extend: "Ext.grid.Panel",
    region: "center",
    height: '200',
    store: Ext.create('Core.Scripts.store.Store'),
    columns: [
        { header: "title", dataIndex: "title" },
        { header: "pages", dataIndex: "pages" }
    ]

});

Ext.define("Core.Scripts.view.DetailViewport", {
    extend: "Ext.container.Viewport",
    frame: true,
    layout: "border",
    initComponent: function () {
        this.items = [new Core.Scripts.view.GridPanel];
        this.callParent(arguments);     
    }

});
Ext.onReady(function () {
    var viewPort = new Core.Scripts.view.DetailViewport();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM