paging.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. Ext.Loader.setConfig({enabled: true});
  2. Ext.Loader.setPath('Ext.ux', '../ux/');
  3. Ext.require([
  4. 'Ext.grid.*',
  5. 'Ext.data.*',
  6. 'Ext.util.*',
  7. 'Ext.toolbar.Paging',
  8. 'Ext.ux.PreviewPlugin',
  9. 'Ext.ModelManager',
  10. 'Ext.tip.QuickTipManager'
  11. ]);
  12. Ext.onReady(function(){
  13. Ext.tip.QuickTipManager.init();
  14. Ext.define('ForumThread', {
  15. extend: 'Ext.data.Model',
  16. fields: [
  17. 'title', 'forumtitle', 'forumid', 'username',
  18. {name: 'replycount', type: 'int'},
  19. {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
  20. 'lastposter', 'excerpt', 'threadid'
  21. ],
  22. idProperty: 'threadid'
  23. });
  24. // create the Data Store
  25. var store = Ext.create('Ext.data.Store', {
  26. pageSize: 50,
  27. model: 'ForumThread',
  28. remoteSort: true,
  29. proxy: {
  30. // load using script tags for cross domain, if the data in on the same domain as
  31. // this page, an HttpProxy would be better
  32. type: 'jsonp',
  33. url: 'http://www.sencha.com/forum/topics-browse-remote.php',
  34. reader: {
  35. root: 'topics',
  36. totalProperty: 'totalCount'
  37. },
  38. // sends single sort as multi parameter
  39. simpleSortMode: true
  40. },
  41. sorters: [{
  42. property: 'lastpost',
  43. direction: 'DESC'
  44. }]
  45. });
  46. // pluggable renders
  47. function renderTopic(value, p, record) {
  48. return Ext.String.format(
  49. '<b><a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a></b><a href="http://sencha.com/forum/forumdisplay.php?f={3}" target="_blank">{1} Forum</a>',
  50. value,
  51. record.data.forumtitle,
  52. record.getId(),
  53. record.data.forumid
  54. );
  55. }
  56. function renderLast(value, p, r) {
  57. return Ext.String.format('{0}<br/>by {1}', Ext.Date.dateFormat(value, 'M j, Y, g:i a'), r.get('lastposter'));
  58. }
  59. var pluginExpanded = true;
  60. var grid = Ext.create('Ext.grid.Panel', {
  61. width: 700,
  62. height: 500,
  63. title: 'ExtJS.com - Browse Forums',
  64. store: store,
  65. disableSelection: true,
  66. loadMask: true,
  67. viewConfig: {
  68. id: 'gv',
  69. trackOver: false,
  70. stripeRows: false,
  71. plugins: [{
  72. ptype: 'preview',
  73. bodyField: 'excerpt',
  74. expanded: true,
  75. pluginId: 'preview'
  76. }]
  77. },
  78. // grid columns
  79. columns:[{
  80. // id assigned so we can apply custom css (e.g. .x-grid-cell-topic b { color:#333 })
  81. // TODO: This poses an issue in subclasses of Grid now because Headers are now Components
  82. // therefore the id will be registered in the ComponentManager and conflict. Need a way to
  83. // add additional CSS classes to the rendered cells.
  84. id: 'topic',
  85. text: "Topic",
  86. dataIndex: 'title',
  87. flex: 1,
  88. renderer: renderTopic,
  89. sortable: false
  90. },{
  91. text: "Author",
  92. dataIndex: 'username',
  93. width: 100,
  94. hidden: true,
  95. sortable: true
  96. },{
  97. text: "Replies",
  98. dataIndex: 'replycount',
  99. width: 70,
  100. align: 'right',
  101. sortable: true
  102. },{
  103. id: 'last',
  104. text: "Last Post",
  105. dataIndex: 'lastpost',
  106. width: 150,
  107. renderer: renderLast,
  108. sortable: true
  109. }],
  110. // paging bar on the bottom
  111. bbar: Ext.create('Ext.PagingToolbar', {
  112. store: store,
  113. displayInfo: true,
  114. displayMsg: 'Displaying topics {0} - {1} of {2}',
  115. emptyMsg: "No topics to display",
  116. items:[
  117. '-', {
  118. text: 'Show Preview',
  119. pressed: pluginExpanded,
  120. enableToggle: true,
  121. toggleHandler: function(btn, pressed) {
  122. var preview = Ext.getCmp('gv').getPlugin('preview');
  123. preview.toggleExpanded(pressed);
  124. }
  125. }]
  126. }),
  127. renderTo: 'topic-grid'
  128. });
  129. // trigger the data store load
  130. store.loadPage(1);
  131. });