480fff71d15c50716ef74c7f600bbbb7368ec3fd.svn-base 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.grid.AbstractGridView = function() {
  7. this.grid = null;
  8. this.events = {
  9. "beforerowremoved" : true,
  10. "beforerowsinserted" : true,
  11. "beforerefresh" : true,
  12. "rowremoved" : true,
  13. "rowsinserted" : true,
  14. "rowupdated" : true,
  15. "refresh" : true
  16. };
  17. Ext.grid.AbstractGridView.superclass.constructor.call(this);
  18. };
  19. Ext.extend(Ext.grid.AbstractGridView, Ext.util.Observable, {
  20. rowClass : "x-grid-row",
  21. cellClass : "x-grid-cell",
  22. tdClass : "x-grid-td",
  23. hdClass : "x-grid-hd",
  24. splitClass : "x-grid-hd-split",
  25. init : function(grid) {
  26. this.grid = grid;
  27. var cid = this.grid.getGridEl().id;
  28. this.colSelector = "#" + cid + " ." + this.cellClass + "-";
  29. this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
  30. this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
  31. this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
  32. },
  33. getColumnRenderers : function() {
  34. var renderers = [];
  35. var cm = this.grid.colModel;
  36. var colCount = cm.getColumnCount();
  37. for (var i = 0; i < colCount; i++) {
  38. renderers[i] = cm.getRenderer(i);
  39. }
  40. return renderers;
  41. },
  42. getColumnIds : function() {
  43. var ids = [];
  44. var cm = this.grid.colModel;
  45. var colCount = cm.getColumnCount();
  46. for (var i = 0; i < colCount; i++) {
  47. ids[i] = cm.getColumnId(i);
  48. }
  49. return ids;
  50. },
  51. getDataIndexes : function() {
  52. if (!this.indexMap) {
  53. this.indexMap = this.buildIndexMap();
  54. }
  55. return this.indexMap.colToData;
  56. },
  57. getColumnIndexByDataIndex : function(dataIndex) {
  58. if (!this.indexMap) {
  59. this.indexMap = this.buildIndexMap();
  60. }
  61. return this.indexMap.dataToCol[dataIndex];
  62. },
  63. /**
  64. * Set a css style for a column dynamically.
  65. *
  66. * @param {Number}
  67. * colIndex The index of the column
  68. * @param {String}
  69. * name The css property name
  70. * @param {String}
  71. * value The css value
  72. */
  73. setCSSStyle : function(colIndex, name, value) {
  74. var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
  75. Ext.util.CSS.updateRule(selector, name, value);
  76. },
  77. generateRules : function(cm) {
  78. var ruleBuf = [];
  79. for (var i = 0, len = cm.getColumnCount(); i < len; i++) {
  80. var cid = cm.getColumnId(i);
  81. ruleBuf.push(this.colSelector, cid, " {\n",
  82. cm.config[i].css, "}\n", this.tdSelector, cid,
  83. " {\n}\n", this.hdSelector, cid, " {\n}\n",
  84. this.splitSelector, cid, " {\n}\n");
  85. }
  86. return Ext.util.CSS.createStyleSheet(ruleBuf.join(""));
  87. }
  88. });