YnColumn.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * 自定义grid.column
  3. * yn即yes/no,显示为是和否,其实际值对应-1和0
  4. */
  5. Ext.define('erp.view.core.grid.YnColumn', {
  6. extend: 'Ext.grid.column.Column',
  7. alias: ['widget.yncolumn'],
  8. trueText: $I18N.common.form.yes,
  9. falseText: $I18N.common.form.no,
  10. constructor: function(cfg){
  11. this.callParent(arguments);
  12. if(!this.readOnly){
  13. this.editor = {
  14. xtype: 'combo',
  15. store: Ext.create('Ext.data.Store', {
  16. fields: ['display', 'value'],
  17. data : [
  18. {"display": $I18N.common.form.yes, "value": -1},
  19. {"display": $I18N.common.form.no, "value": 0}
  20. ]
  21. }),
  22. editable: false,
  23. displayField: 'display',
  24. valueField: 'value',
  25. queryMode: 'local',
  26. value: '0',
  27. hideTrigger: false,
  28. listeners: {
  29. scope: this,
  30. 'change': function(c){
  31. if(c.rawValue != this.trueText && c.rawValue != this.falseText){
  32. //实现grid单元格编辑模式下,不让用户编辑combo
  33. if(contains(c.rawValue, this.falseText, true)){
  34. c.setValue(this.falseText);
  35. } else if(contains(c.rawValue, this.trueText, true)){
  36. c.setValue(this.trueText);
  37. } else {
  38. c.setValue(this.falseText);
  39. }
  40. }
  41. }
  42. }
  43. };
  44. }
  45. var trueText = this.trueText,
  46. falseText = this.falseText;
  47. this.renderer = function(value){
  48. if(value === undefined){
  49. return falseText;
  50. }
  51. if(!value || value == 0){
  52. return '<span style="color:#888;">' + falseText + '</span>';
  53. }
  54. return trueText;
  55. };
  56. },
  57. renderer: function(val){
  58. var res = val;
  59. switch(val){
  60. case 0:
  61. res = $I18N.common.form.no;break;
  62. case -1:
  63. res = $I18N.common.form.yes;break;
  64. case 1:
  65. res = $I18N.common.form.yes;break;
  66. }
  67. return res;
  68. }
  69. });
  70. Ext.data.Types.YN = {
  71. convert : function(v, data) {
  72. if(!v || v == '')
  73. v = '0';
  74. return v;
  75. },
  76. sortType : function(v) {
  77. return v.Latitude;
  78. },
  79. type : 'yn'
  80. };