You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. // create the Data Store
  17. var store = new Ext.data.JsonStore({
  18. root: 'topics',
  19. totalProperty: 'totalCount',
  20. idProperty: 'threadid',
  21. remoteSort: true,
  22. fields: [
  23. 'title', 'forumtitle', 'forumid', 'author',
  24. {name: 'replycount', type: 'int'},
  25. {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
  26. 'lastposter', 'excerpt'
  27. ],
  28. // load using script tags for cross domain, if the data in on the same domain as
  29. // this page, an HttpProxy would be better
  30. proxy: new Ext.data.ScriptTagProxy({
  31. url: 'http://extjs.com/forum/topics-browse-remote.php'
  32. })
  33. });
  34. store.setDefaultSort('lastpost', 'desc');
  35. // pluggable renders
  36. function renderTopic(value, p, record){
  37. return String.format(
  38. '<b><a href="http://extjs.com/forum/showthread.php?t={2}" target="_blank">{0}</a></b><a href="http://extjs.com/forum/forumdisplay.php?f={3}" target="_blank">{1} Forum</a>',
  39. value, record.data.forumtitle, record.id, record.data.forumid);
  40. }
  41. function renderLast(value, p, r){
  42. return String.format('{0}<br/>by {1}', value.dateFormat('M j, Y, g:i a'), r.data['lastposter']);
  43. }
  44. var grid = new Ext.grid.GridPanel({
  45. width:700,
  46. height:500,
  47. title:'ExtJS.com - Browse Forums',
  48. store: store,
  49. trackMouseOver:false,
  50. disableSelection:true,
  51. loadMask: true,
  52. // grid columns
  53. columns:[{
  54. id: 'topic', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
  55. header: "Topic",
  56. dataIndex: 'title',
  57. width: 420,
  58. renderer: renderTopic,
  59. sortable: true
  60. },{
  61. header: "Author",
  62. dataIndex: 'author',
  63. width: 100,
  64. hidden: true,
  65. sortable: true
  66. },{
  67. header: "Replies",
  68. dataIndex: 'replycount',
  69. width: 70,
  70. align: 'right',
  71. sortable: true
  72. },{
  73. id: 'last',
  74. header: "Last Post",
  75. dataIndex: 'lastpost',
  76. width: 150,
  77. renderer: renderLast,
  78. sortable: true
  79. }],
  80. // customize view config
  81. viewConfig: {
  82. forceFit:true,
  83. enableRowBody:true,
  84. showPreview:true,
  85. getRowClass : function(record, rowIndex, p, store){
  86. if(this.showPreview){
  87. p.body = '<p>'+record.data.excerpt+'</p>';
  88. return 'x-grid3-row-expanded';
  89. }
  90. return 'x-grid3-row-collapsed';
  91. }
  92. },
  93. // paging bar on the bottom
  94. bbar: new Ext.PagingToolbar({
  95. pageSize: 25,
  96. store: store,
  97. displayInfo: true,
  98. displayMsg: 'Displaying topics {0} - {1} of {2}',
  99. emptyMsg: "No topics to display",
  100. items:[
  101. '-', {
  102. pressed: true,
  103. enableToggle:true,
  104. text: 'Show Preview',
  105. cls: 'x-btn-text-icon details',
  106. toggleHandler: function(btn, pressed){
  107. var view = grid.getView();
  108. view.showPreview = pressed;
  109. view.refresh();
  110. }
  111. }]
  112. })
  113. });
  114. // render it
  115. grid.render('topic-grid');
  116. // trigger the data store load
  117. store.load({params:{start:0, limit:25}});
  118. });