SlidingPager.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @class Ext.ux.SlidingPager
  3. * @extends Object
  4. * Plugin for PagingToolbar which replaces the textfield input with a slider
  5. * @constructor
  6. * Create a new ItemSelector
  7. * @param {Object} config Configuration options
  8. */
  9. Ext.define('Ext.ux.SlidingPager', {
  10. requires: [
  11. 'Ext.slider.Single',
  12. 'Ext.slider.Tip'
  13. ],
  14. constructor : function(config) {
  15. if (config) {
  16. Ext.apply(this, config);
  17. }
  18. },
  19. init : function(pbar){
  20. var idx = pbar.items.indexOf(pbar.child("#inputItem")),
  21. slider;
  22. Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
  23. c.hide();
  24. });
  25. slider = Ext.create('Ext.slider.Single', {
  26. width: 114,
  27. minValue: 1,
  28. maxValue: 1,
  29. hideLabel: true,
  30. tipText: function(thumb) {
  31. return Ext.String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
  32. },
  33. listeners: {
  34. changecomplete: function(s, v){
  35. pbar.store.loadPage(v);
  36. }
  37. }
  38. });
  39. pbar.insert(idx + 1, slider);
  40. pbar.on({
  41. change: function(pb, data){
  42. slider.setMaxValue(data.pageCount);
  43. slider.setValue(data.currentPage);
  44. }
  45. });
  46. }
  47. });