paging.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.onReady(function() {
  7. // create the Data Store
  8. var store = new Ext.data.Store({
  9. // load using script tags for cross domain, if the data in on
  10. // the same domain as
  11. // this page, an HttpProxy would be better
  12. proxy : new Ext.data.ScriptTagProxy({
  13. url : 'http://extjs.com/forum/topics-browse-remote.php'
  14. }),
  15. // create reader that reads the Topic records
  16. reader : new Ext.data.JsonReader({
  17. root : 'topics',
  18. totalProperty : 'totalCount',
  19. // id: 'threadid',
  20. fields : ['title', 'forumtitle', 'forumid',
  21. 'author', {
  22. name : 'replycount',
  23. type : 'int'
  24. }, {
  25. name : 'lastpost',
  26. mapping : 'lastpost',
  27. type : 'date',
  28. dateFormat : 'timestamp'
  29. }, 'lastposter', 'excerpt']
  30. }),
  31. // turn on remote sorting
  32. remoteSort : true
  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}"
  39. // target="_blank">{0}</a></b><a
  40. // href="http://extjs.com/forum/forumdisplay.php?f={3}"
  41. // target="_blank">{1} Forum</a>',
  42. value, record.data.forumtitle, record.id, record.data.forumid);
  43. }
  44. function renderLast(value, p, r) {
  45. return String.format('{0}<br/>by {1}', value
  46. .dateFormat('M j, Y, g:i a'), r.data['lastposter']);
  47. }
  48. // the column model has information about grid columns
  49. // dataIndex maps the column to the specific data field in
  50. // the data store
  51. var cm = new Ext.grid.ColumnModel([{
  52. id : 'topic', // id assigned so we can apply custom css (e.g.
  53. // .x-grid-col-topic b { color:#333 })
  54. header : "Topic",
  55. dataIndex : 'title',
  56. width : 420,
  57. renderer : renderTopic
  58. }, {
  59. header : "Author",
  60. dataIndex : 'author',
  61. width : 100,
  62. hidden : true
  63. }, {
  64. header : "Replies",
  65. dataIndex : 'replycount',
  66. width : 70,
  67. align : 'right'
  68. }, {
  69. id : 'last',
  70. header : "Last Post",
  71. dataIndex : 'lastpost',
  72. width : 150,
  73. renderer : renderLast
  74. }]);
  75. // by default columns are sortable
  76. // cm.defaultSortable = true;
  77. var grid = new Ext.grid.GridPanel({
  78. el : 'topic-grid',
  79. width : 700,
  80. height : 500,
  81. title : 'ExtJS.com - Browse Forums',
  82. store : store,
  83. cm : cm,
  84. trackMouseOver : false,
  85. sm : new Ext.grid.RowSelectionModel({
  86. selectRow : Ext.emptyFn
  87. }),
  88. loadMask : true,
  89. /*
  90. * viewConfig: { forceFit:true, enableRowBody:true,
  91. * showPreview:true, getRowClass : function(record, rowIndex, p,
  92. * store){ if(this.showPreview){ p.body = '<p>'+record.data.excerpt+'</p>';
  93. * return 'x-grid3-row-expanded'; } return
  94. * 'x-grid3-row-collapsed'; } },
  95. */
  96. bbar : new Ext.PagingToolbar({
  97. pageSize : 25,
  98. store : store,
  99. displayInfo : true,
  100. displayMsg : 'Displaying topics {0} - {1} of {2}',
  101. emptyMsg : "No topics to display",
  102. items : ['-', {
  103. pressed : true,
  104. enableToggle : true,
  105. text : 'Show Preview',
  106. cls : 'x-btn-text-icon details',
  107. toggleHandler : toggleDetails
  108. }]
  109. })
  110. });
  111. // render it
  112. grid.render();
  113. // trigger the data store load
  114. store.load({
  115. params : {
  116. start : 0,
  117. limit : 25
  118. }
  119. });
  120. function toggleDetails(btn, pressed) {
  121. var view = grid.getView();
  122. view.showPreview = pressed;
  123. view.refresh();
  124. }
  125. });