tree.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. define("dojox/grid/cells/tree", [
  2. "dojo/_base/kernel",
  3. "../../main",
  4. "dojo/_base/lang",
  5. "../cells"
  6. ], function(dojo, dojox, lang){
  7. dojox.grid.cells.TreeCell = {
  8. formatAggregate: function(inItem, level, inRowIndexes){
  9. var f, g=this.grid, i=g.edit.info,
  10. d=g.aggregator ? g.aggregator.getForCell(this, level, inItem, level === this.level ? "cnt" : this.parentCell.aggregate) : (this.value || this.defaultValue);
  11. return this._defaultFormat(d, [d, level - this.level, inRowIndexes, this]);
  12. },
  13. formatIndexes: function(inRowIndexes, inItem){
  14. var f, g=this.grid, i=g.edit.info,
  15. d=this.get ? this.get(inRowIndexes[0], inItem, inRowIndexes) : (this.value || this.defaultValue);
  16. if(this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndexes[0] && i.cell==this))){
  17. return this.formatEditing(d, inRowIndexes[0], inRowIndexes);
  18. }else{
  19. return this._defaultFormat(d, [d, inRowIndexes[0], inRowIndexes, this]);
  20. }
  21. },
  22. getOpenState: function(itemId){
  23. var grid = this.grid, store = grid.store, itm = null;
  24. if(store.isItem(itemId)){
  25. itm = itemId;
  26. itemId = store.getIdentity(itemId);
  27. }
  28. if(!this.openStates){ this.openStates = {}; }
  29. if(typeof itemId != "string" || !(itemId in this.openStates)){
  30. this.openStates[itemId] = grid.getDefaultOpenState(this, itm);
  31. }
  32. return this.openStates[itemId];
  33. },
  34. formatAtLevel: function(inRowIndexes, inItem, level, summaryRow, toggleClass, cellClasses){
  35. if(!lang.isArray(inRowIndexes)){
  36. inRowIndexes = [inRowIndexes];
  37. }
  38. var result = "";
  39. if(level > this.level || (level === this.level && summaryRow)){
  40. cellClasses.push("dojoxGridSpacerCell");
  41. if(level === this.level){
  42. cellClasses.push("dojoxGridTotalCell");
  43. }
  44. result = '<span></span>';
  45. }else if(level < this.level){
  46. cellClasses.push("dojoxGridSummaryCell");
  47. result = '<span class="dojoxGridSummarySpan">' + this.formatAggregate(inItem, level, inRowIndexes) + '</span>';
  48. }else{
  49. var ret = "";
  50. if(this.isCollapsable){
  51. var store = this.grid.store, id = "";
  52. if(store.isItem(inItem)){
  53. id = store.getIdentity(inItem);
  54. }
  55. cellClasses.push("dojoxGridExpandoCell");
  56. ret = '<span ' + dojo._scopeName + 'Type="dojox.grid._Expando" level="' + level + '" class="dojoxGridExpando"' +
  57. '" toggleClass="' + toggleClass + '" itemId="' + id + '" cellIdx="' + this.index + '"></span>';
  58. }
  59. result = ret + this.formatIndexes(inRowIndexes, inItem);
  60. }
  61. if(this.grid.focus.cell && this.index == this.grid.focus.cell.index &&
  62. inRowIndexes.join('/') == this.grid.focus.rowIndex){
  63. cellClasses.push(this.grid.focus.focusClass);
  64. }
  65. return result;
  66. }
  67. };
  68. return dojox.grid.cells.TreeCell;
  69. });