将分页工具栏与网格面板结合使用

发布于 2024-11-14 06:17:59 字数 1918 浏览 2 评论 0原文

我已经被困在这一点上很长一段时间了。请帮助我找出我的错误。

我试图在网格面板中显示数据,由于数据很大,我也使用分页工具栏。这是我的代码(我不确定,但我认为问题出在我正在创建的存储上)。

var myData = {
  record: [{
      name: "Record 0",
      column1: "0",
      column2: "0"
    }, {
      name: "Record 1",
      column1: "1",
      column2: "1"
    }, {
      name: "Record 2",
      column1: "2",
      column2: "2"
    },
  ]
};
var fields = [{
    name: 'name',
    mapping: 'name'
  }, {
    name: 'column1',
    mapping: 'column1'
  }, {
    name: 'column2',
    mapping: 'column2'
  }
];
var store = new Ext.data.Store({
  id: 'simpsonsStore',
  fields: ['name', 'column1', 'column2'],
  pageSize: 5, // items per page
  data: myData,
  reader: {
    root: 'record',
    type: 'json'
  }
});
// Column Model shortcut array
var cols = [{
    id: 'name',
    header: "Record Name",
    width: 50,
    sortable: true,
    dataIndex: 'name'
  }, {
    header: "column1",
    width: 50,
    sortable: true,
    dataIndex: 'column1'
  }, {
    header: "column2",
    width: 50,
    sortable: true,
    dataIndex: 'column2'
  }
];
store.load({
  params: {
    start: 0,
    limit: 5
  }
});
// declare the source Grid
var grid = new Ext.grid.GridPanel({
  ddGroup: 'gridDDGroup',
  store: store,
  columns: cols,
  enableDragDrop: true,
  stripeRows: true,
  autoExpandColumn: 'name',
  width: 650,
  height: 325,
  region: 'west',
  title: 'Data Grid',
  selModel: new Ext.grid.RowSelectionModel({
    singleSelect: true
  }),
  dockedItems: [{
      xtype: 'pagingtoolbar',
      store: store, // same store GridPanel is using
      dock: 'bottom',
      displayInfo: true
    }
  ]
});
var displayPanel = new Ext.Panel({
  width: 650,
  height: 300,
  layout: 'column',
  renderTo: Ext.getBody(),
  items: [
    grid
  ],
  bbar: [
      '->', {
      text: 'Reset Example',
      handler: function () {
        gridStore.loadData(myData);
      }
    }
  ]
});

I am stuck at this point since a long time. Please help me identify my error.

I am trying to show data in grid panel and since data is large I am also using Paging Toolbar. This is my code (I am not sure but I think problem is in store that I am creating).

var myData = {
  record: [{
      name: "Record 0",
      column1: "0",
      column2: "0"
    }, {
      name: "Record 1",
      column1: "1",
      column2: "1"
    }, {
      name: "Record 2",
      column1: "2",
      column2: "2"
    },
  ]
};
var fields = [{
    name: 'name',
    mapping: 'name'
  }, {
    name: 'column1',
    mapping: 'column1'
  }, {
    name: 'column2',
    mapping: 'column2'
  }
];
var store = new Ext.data.Store({
  id: 'simpsonsStore',
  fields: ['name', 'column1', 'column2'],
  pageSize: 5, // items per page
  data: myData,
  reader: {
    root: 'record',
    type: 'json'
  }
});
// Column Model shortcut array
var cols = [{
    id: 'name',
    header: "Record Name",
    width: 50,
    sortable: true,
    dataIndex: 'name'
  }, {
    header: "column1",
    width: 50,
    sortable: true,
    dataIndex: 'column1'
  }, {
    header: "column2",
    width: 50,
    sortable: true,
    dataIndex: 'column2'
  }
];
store.load({
  params: {
    start: 0,
    limit: 5
  }
});
// declare the source Grid
var grid = new Ext.grid.GridPanel({
  ddGroup: 'gridDDGroup',
  store: store,
  columns: cols,
  enableDragDrop: true,
  stripeRows: true,
  autoExpandColumn: 'name',
  width: 650,
  height: 325,
  region: 'west',
  title: 'Data Grid',
  selModel: new Ext.grid.RowSelectionModel({
    singleSelect: true
  }),
  dockedItems: [{
      xtype: 'pagingtoolbar',
      store: store, // same store GridPanel is using
      dock: 'bottom',
      displayInfo: true
    }
  ]
});
var displayPanel = new Ext.Panel({
  width: 650,
  height: 300,
  layout: 'column',
  renderTo: Ext.getBody(),
  items: [
    grid
  ],
  bbar: [
      '->', {
      text: 'Reset Example',
      handler: function () {
        gridStore.loadData(myData);
      }
    }
  ]
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲念泪 2024-11-21 06:17:59

myData.record 数组上以多余的逗号开头将阻止其运行。

var myData = {
            record : [
              { name : "Record 0", column1 : "0", column2 : "0" },
              { name : "Record 1", column1 : "1", column2 : "1" },       
              { name : "Record 2", column1 : "2", column2 : "2" }**,**
            ]
    };

To start with the extraneous comma on your myData.record array will prevent this from running.

var myData = {
            record : [
              { name : "Record 0", column1 : "0", column2 : "0" },
              { name : "Record 1", column1 : "1", column2 : "1" },       
              { name : "Record 2", column1 : "2", column2 : "2" }**,**
            ]
    };
夏花。依旧 2024-11-21 06:17:59

尝试在网格 bbar 处设置分页栏,而不是停靠项目。
新的 Ext.PagingToolbar({
页面大小:20,
商店: 商店,
显示信息:true
});

Instead of dockedItems try setting pagination bar at grid bbar.
new Ext.PagingToolbar({
pageSize : 20,
store : store,
displayInfo : true
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文