YnColumnNV.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * 自定义grid.column(无默认值)
  3. * yn即yes/no,显示为是和否,其实际值对应-1和0
  4. */
  5. Ext.define('erp.view.core.grid.YnColumnNV', {
  6. extend: 'Ext.grid.column.Column',
  7. alias: ['widget.ynnvcolumn'],
  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. hideTrigger: false,
  27. value: null,
  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. necessary = this.logic == 'necessaryField';
  48. this.renderer = function(value){
  49. var val = '';
  50. if(value == '-1' || value == '1'){
  51. val = trueText;
  52. } else if(value == '0') {
  53. val = falseText;
  54. }
  55. necessary && val == '' && (val = '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  56. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>');
  57. return val;
  58. };
  59. }
  60. });
  61. //Ext.data.Types.YNNV = {
  62. // convert : function(v, data) {
  63. // return v;
  64. // },
  65. // sortType : function(v) {
  66. // return v.Latitude;
  67. // },
  68. // type : 'ynnv'
  69. //};