CheckColumn.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Ext.define('saas.override.grid.column.CheckColumn', {
  2. override: 'Ext.grid.column.Check',
  3. /**
  4. * 是否switch模式
  5. */
  6. switch: false,
  7. switchOffCls: Ext.baseCSSPrefix + 'grid-switchcolumn',
  8. switchOnCls: Ext.baseCSSPrefix + 'grid-switchcolumn-checked',
  9. constructor: function (config) {
  10. config = config || {};
  11. if (config.switch) {
  12. config.checkboxCls = this.switchOffCls;
  13. config.checkboxCheckedCls = this.switchOnCls;
  14. }
  15. this.scope = this;
  16. this.callParent([
  17. config
  18. ]);
  19. },
  20. defaultRenderer: function (value, cellValues, a, b, c, d, e, f) {
  21. var me = this,
  22. cls = me.checkboxCls,
  23. tip = '';
  24. if (me.invert) {
  25. value = !value;
  26. }
  27. if (me.disabled) {
  28. cellValues.tdCls += ' ' + me.disabledCls;
  29. }
  30. if (value) {
  31. cls += ' ' + me.checkboxCheckedCls;
  32. tip = me.checkedTooltip;
  33. } else {
  34. tip = me.tooltip;
  35. }
  36. if (tip) {
  37. cellValues.tdAttr += ' data-qtip="' + Ext.htmlEncode(tip) + '"';
  38. }
  39. if (me.useAriaElements) {
  40. cellValues.tdAttr += ' aria-describedby="' + me.id + '-cell-description' + (!value ? '-not' : '') + '-selected"';
  41. }
  42. // This will update the header state on the next animation frame
  43. // after all rows have been rendered.
  44. me.updateHeaderState();
  45. if (typeof value == 'object' && value == null) {
  46. cellValues.style = 'display: none;';
  47. cellValues.tdCls += ' ' + me.disabledCls;
  48. cellValues.innerCls = me.disabledCls;
  49. cellValues.classes.push(me.disabledCls);
  50. cellValues.cellRole = me.disabledCls;
  51. return '<span style="display: none;" class="' + me.disabledCls + '"></span>'
  52. }
  53. //hideCheckField hideCheckVal
  54. //根据 某个字段 判断该行的checkbox 是否要隐藏 ,后期可拓展
  55. if (e.selModel && e.selModel.hideCheckField) {
  56. var field = e.selModel.hideCheckField;
  57. var checkVal = e.selModel.hideCheckVal;
  58. if (a.get(field) == checkVal) {
  59. cellValues.style = 'display: none;';
  60. cellValues.tdCls += ' ' + me.disabledCls;
  61. cellValues.innerCls = me.disabledCls;
  62. cellValues.classes.push(me.disabledCls);
  63. cellValues.cellRole = me.disabledCls;
  64. return '<span style="display: none;" class="' + me.disabledCls + '"></span>'
  65. }
  66. }
  67. return '<span class="' + cls + '" role="' + me.checkboxAriaRole + '"' + (!me.ariaStaticRoles[me.checkboxAriaRole] ? ' tabIndex="0"' : '') + '></span>';
  68. },
  69. updater: function (cell, value) {
  70. var me = this,
  71. tip;
  72. if (me.invert) {
  73. value = !value;
  74. }
  75. if (value) {
  76. tip = me.checkedTooltip;
  77. } else {
  78. tip = me.tooltip;
  79. }
  80. if (tip) {
  81. cell.setAttribute('data-qtip', tip);
  82. } else {
  83. cell.removeAttribute('data-qtip');
  84. }
  85. if (me.useAriaElements) {
  86. me.updateCellAriaDescription(null, value, cell);
  87. }
  88. cell = Ext.fly(cell);
  89. cell[me.disabled ? 'addCls' : 'removeCls'](me.disabledCls);
  90. Ext.fly(cell.down(me.getView().innerSelector, true).firstChild)[value ? 'addCls' : 'removeCls'](me.checkboxCheckedCls);
  91. // This will update the header state on the next animation frame
  92. // after all rows have been updated.
  93. me.updateHeaderState();
  94. }
  95. });