infinite-scroll.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. Ext.require([
  2. 'Ext.grid.*',
  3. 'Ext.data.*',
  4. 'Ext.util.*',
  5. 'Ext.grid.PagingScroller'
  6. ]);
  7. Ext.onReady(function(){
  8. Ext.define('ForumThread', {
  9. extend: 'Ext.data.Model',
  10. fields: [
  11. 'title', 'forumtitle', 'forumid', 'username', {
  12. name: 'replycount',
  13. type: 'int'
  14. }, {
  15. name: 'lastpost',
  16. mapping: 'lastpost',
  17. type: 'date',
  18. dateFormat: 'timestamp'
  19. },
  20. 'lastposter', 'excerpt', 'threadid'
  21. ],
  22. idProperty: 'threadid'
  23. });
  24. // create the Data Store
  25. var store = Ext.create('Ext.data.Store', {
  26. id: 'store',
  27. model: 'ForumThread',
  28. remoteGroup: true,
  29. // allow the grid to interact with the paging scroller by buffering
  30. buffered: true,
  31. leadingBufferZone: 300,
  32. pageSize: 100,
  33. proxy: {
  34. // load using script tags for cross domain, if the data in on the same domain as
  35. // this page, an Ajax proxy would be better
  36. type: 'jsonp',
  37. url: 'http://www.sencha.com/forum/remote_topics/index.php',
  38. reader: {
  39. root: 'topics',
  40. totalProperty: 'totalCount'
  41. },
  42. // sends single sort as multi parameter
  43. simpleSortMode: true,
  44. // sends single group as multi parameter
  45. simpleGroupMode: true,
  46. // This particular service cannot sort on more than one field, so grouping === sorting.
  47. groupParam: 'sort',
  48. groupDirectionParam: 'dir'
  49. },
  50. sorters: [{
  51. property: 'threadid',
  52. direction: 'ASC'
  53. }],
  54. autoLoad: true,
  55. listeners: {
  56. // This particular service cannot sort on more than one field, so if grouped, disable sorting
  57. groupchange: function(store, groupers) {
  58. var sortable = !store.isGrouped(),
  59. headers = grid.headerCt.getVisibleGridColumns(),
  60. i, len = headers.length;
  61. for (i = 0; i < len; i++) {
  62. headers[i].sortable = (headers[i].sortable !== undefined) ? headers[i].sortable : sortable;
  63. }
  64. },
  65. // This particular service cannot sort on more than one field, so if grouped, disable sorting
  66. beforeprefetch: function(store, operation) {
  67. if (operation.groupers && operation.groupers.length) {
  68. delete operation.sorters;
  69. }
  70. }
  71. }
  72. });
  73. function renderTopic(value, p, record) {
  74. return Ext.String.format(
  75. '<a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a>',
  76. value,
  77. record.data.forumtitle,
  78. record.getId(),
  79. record.data.forumid
  80. );
  81. }
  82. var grid = Ext.create('Ext.grid.Panel', {
  83. width: 700,
  84. height: 500,
  85. collapsible: true,
  86. title: 'ExtJS.com - Browse Forums',
  87. store: store,
  88. loadMask: true,
  89. selModel: {
  90. pruneRemoved: false
  91. },
  92. multiSelect: true,
  93. viewConfig: {
  94. trackOver: false
  95. },
  96. features:[{
  97. ftype: 'grouping',
  98. hideGroupedHeader: false
  99. }],
  100. verticalScroller:{
  101. variableRowHeight: true
  102. },
  103. // grid columns
  104. columns:[{
  105. xtype: 'rownumberer',
  106. width: 50,
  107. sortable: false
  108. },{
  109. tdCls: 'x-grid-cell-topic',
  110. text: "Topic",
  111. dataIndex: 'title',
  112. flex: 1,
  113. renderer: renderTopic,
  114. sortable: true
  115. },{
  116. text: "Author",
  117. dataIndex: 'username',
  118. width: 100,
  119. hidden: true,
  120. sortable: true
  121. },{
  122. text: "Replies",
  123. dataIndex: 'replycount',
  124. align: 'center',
  125. width: 70,
  126. sortable: false
  127. },{
  128. id: 'last',
  129. text: "Last Post",
  130. dataIndex: 'lastpost',
  131. width: 130,
  132. renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
  133. sortable: true,
  134. groupable: false
  135. }],
  136. renderTo: Ext.getBody()
  137. });
  138. });