修改column.js文件,做是否值为复选框

修改checkColumn.js文件

/*!
 * Ext JS Library 3.1.1
 * Copyright(c) 2006-2010 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
Ext.ns('Ext.ux.grid');/**
 * @class Ext.ux.grid.CheckColumn
 * @extends Object
 * GridPanel plugin to add a column with check boxes to a grid.
 * <p>Example usage:</p>
 * <pre><code>
// create the column
var checkColumn = new Ext.grid.CheckColumn({
   header: 'Indoor?',
   dataIndex: 'indoor',
   id: 'check',
   width: 55
});// add the column to the column model
var cm = new Ext.grid.ColumnModel([{
       header: 'Foo',
       ...
    },
    checkColumn
]);// create the grid
var grid = new Ext.grid.EditorGridPanel({
    ...
    cm: cm,
    plugins: [checkColumn], // include plugin
    ...
});
 * </code></pre>
 * In addition to storing a Boolean value within the record data, this
 * class toggles a css class between <tt>'x-grid3-check-col'</tt> and
 * <tt>'x-grid3-check-col-on'</tt> to alter the background image used for
 * a column.
 */
Ext.ux.grid.CheckColumn = function(config){
    Ext.apply(this, config);
    if(!this.id){
        this.id = Ext.id();
    }
    this.renderer = this.renderer.createDelegate(this);
};Ext.ux.grid.CheckColumn.prototype ={
    init : function(grid){
        this.grid = grid;
        this.grid.on('render', function(){
            var view = this.grid.getView();
            view.mainBody.on('mousedown', this.onMouseDown, this);
        }, this);
    },  
    onMouseDown : function(e, t){
        if(Ext.fly(t).hasClass(this.createId())){
            e.stopEvent();
            var index = this.grid.getView().findRowIndex(t);
            var record = this.grid.store.getAt(index);
            var value = record.data[this.dataIndex];
         switch(value)
         {
             case '0':
               value = 'N';
               break;
             case '1':
               value = 'Y';
               break;
             default:
               value = !value;
         }
            record.set(this.dataIndex, value);
        }
    }, 
    renderer : function(v, p, record){
     p.css += ' x-grid3-check-col-td';
     return String.format('<div class="x-grid3-check-col{0} {1}">&nbsp;</div>',   v=='Y' || v== true ? '-on' : '', this.createId());
    },
   
    createId : function(){
        return 'x-grid3-cc-' + this.id;
    }
};// register ptype
Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);// backwards compat
Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;

前台引用:

Ext.namespace("ssi.busi");
ssi.busi.TemplateCfgList = function(config) {
 Ext.apply(this, config);
 this.initialize();
};

ssi.busi.TemplateCfgList.prototype = {
 initialize : function() {
  var win = new Ext.Viewport({
   layout : 'fit',
   items : [ this.getGrid() ],
   renderTo : Ext.getBody()
  });
  win.show();
  win.doLayout(true, true);
 },

 getGrid : function() {
  if (this.grid == null) {
   var store = new Ext.data.Store(
     {
      proxy : new Ext.data.HttpProxy(
        {
         url : this.rootPath
           + "/busi/templateCfg_getTemplateCfgData.do?busiTypeId="
           + this.busiTypeId
        }),
      reader : new Ext.data.JsonReader({
       root : "rows",
       totalProperty : "totalCount"
      }, [ {
       name : "baseTemplateId"
      }, {
       name : "sheet"
      }, {
       name : "x"
      }, {
       name : "defineFlag"
      }, {
       name : "defineId"
      }, {
       name : "defaultValue"
      }, {
       name : "valNull"
      }, {
       name : "defineGroup"
      }, {
       name : "genFlag"
      }, {
       name : "baseTemplateName"
      }, {
       name : "defineName"
      } ])
     });
   var sm = new Ext.grid.CheckboxSelectionModel();
   var defineFlagStore = new Ext.data.ArrayStore({
    fields : [ 'myId', 'displayText' ],
    data : [ [ 0, '共有' ], [ 1, '借方' ], [ 2, '贷方' ] ]
   });
   
   var defineIdStore = new Ext.data.JsonStore({
    url : this.rootPath
      + "/busi/templateCfg_getDefineNameData.do",
    root : 'root',
    autoLoad : true,
    fields : [
      'defineId',
      'defineName' ]
    });
   var checkColumn =new Ext.grid.CheckColumn({
          header: '自动生成值',
          dataIndex: 'genFlag',
          width: 70
       });
   var isNull =new Ext.grid.CheckColumn({
          header: '是否必填',
          dataIndex: 'valNull',
          width: 70
       });
   var cm = new Ext.grid.ColumnModel(
     {
      columns : [
        sm,
        new Ext.grid.RowNumberer(),
        {
         header : '模板名称',
         width : 120,
         dataIndex : 'baseTemplateName',
         editor : {
          xtype : 'textfield'
         }
        },
        {
         header : '表格页签',
         width : 80,
         dataIndex : 'sheet',
         editor : {
          xtype : 'textfield'
         }
        },
        {
         header : '列',
         width : 30,
         dataIndex : 'x',
         editor : {
          xtype : 'textfield'
         }
        },
        {
         header : '资产变动',
         width : 70,
         dataIndex : 'defineFlag',
         editor : new Ext.form.ComboBox({
          typeAhead : true,
          triggerAction : 'all',
          mode : 'local',
          editable : false,
          forceSelection : true,
          id : "define_combo",
          hiddenName : 'defineFlag',// 提交到后台的input的name
          store : defineFlagStore,
          valueField : 'myId',
          displayField : 'displayText',
          allowBlank : false,
          triggerAction : 'all'
         }),
         renderer : function(value, cellmeta, record) {
          var index = defineFlagStore
            .find(Ext.getCmp('define_combo').valueField,value);
          var record = defineFlagStore.getAt(index);
          var displayText = "";
          if (record == null) {
           displayText = value;
          } else {
           displayText = record.data.displayText;//
          }
          return displayText;
         }

        },
        {
         header : '表单名称',
         width : 150,
         dataIndex : 'defineId',
         id : "defineId",
         editor : new Ext.form.ComboBox({
           triggerAction : 'all',
           editable : false,
           scope : this,
           forceSelection : true,
           id : "defineId_combo",
           hiddenName : 'defineId',// 提交到后台的input的name
           store : defineIdStore,
           valueField : 'defineId',
           displayField : 'defineName',
           allowBlank : false,
           triggerAction : 'all'
          }),
         renderer : function(value, cellmeta, record) {
          var index = defineIdStore
            .find(Ext.getCmp('defineId_combo').valueField,value);
          var record = defineIdStore.getAt(index);
          var displayText = "";
          if (record == null) {
           displayText = value;
          } else {
           displayText = record.data.defineName;//
          }
          return displayText;
         }
        }, {
         header : '默认值',
         width : 90,
         dataIndex : 'defaultValue',
         editor : {
          xtype : 'textfield'
         }
        }, {
         header : '分号组',
         width : 90,
         dataIndex : 'defineGroup',
         editor : {
          xtype : 'textfield'
         }
        }, {
         header : 'baseTemplateId',
         width : 90,
         dataIndex : 'baseTemplateId',
         hidden : true

        },isNull,checkColumn ],
      defaults : {
       sortable : true,
       menuDisabled : false,
       width : 90
      }
     });
   this.grid = new Ext.grid.EditorGridPanel({
    region : 'center',
    loadMask : true,
    authWidth : true,
    cm : cm,
    sm : sm,
    clicksToEdit : 1,
    plugins: [isNull,checkColumn],
    store : store,
    tbar : this.createToolbar(),
    bbar : new Ext.PagingToolbar({
     pageSize : 25,
     store : store,
     displayInfo : true,
     displayMsg : '',
     emptyMsg : "",
     beforePageText : '第',
     afterPageText : '/ {0}'
    }),
    listeners : {
     afterrender : function() {
      this.grid.getBottomToolbar().doRefresh();
     },

     scope : this
    }
   });
  }
  return this.grid;
 },

 createToolbar : function() {
  return new Ext.Toolbar({
   scope : this,
   items : [ {
    text : '增加记录',
    scope : this,
    icon : this.rootPath + '/resources/images/toolbar/add.gif',
    handler : function() {
     var Plant = this.grid.getStore().recordType;
     var p = new Plant({
      baseTemplateId : this.busiTypeId,
      sheet : 0,
      x : 0,
      defineFlag : '',
      defineId : '',
      defaultValue : '',
      valNull : '',
      defineGroup : '',
      genFlag : ''
     });
     this.grid.stopEditing();
     this.grid.getStore().insert(0, p);
     this.grid.startEditing(0, 0);
    }
   }, {
    text : '删除新增记录',
    icon : this.rootPath + '/resources/images/toolbar/delete.gif',
    scope : this,
    handler : function() {
     this.grid.stopEditing();
     var s = this.grid.getSelectionModel().getSelections();
     if (s.length == 0) {
      alert('请至少选择一个记录');
      return;
     }
     if (!confirm("确认删除?")) {
      return;
     }
     for ( var i = 0, r; r = s[i]; i++) {
      this.grid.getStore().remove(r);
     }
    }
   }, '-', new ssi.auth.Action({
    text : "删除",
    icon : this.rootPath + '/resources/images/toolbar/delete.png',
    auths : this.auths,
    authorityId : 'USER_DEL',
    listeners : {
     click : this.del,
     scope : this
    }
   }), new ssi.auth.Action({
    text : "保存",
    icon : this.rootPath + '/resources/images/toolbar/save.png',
    auths : this.auths,
    authorityId : 'USER_ADD',
    listeners : {
     click : this.add,
     scope : this
    }
   }), new ssi.auth.Action({
    text : "撤销",
    icon : this.rootPath + '/resources/images/toolbar/back.gif',
    auths : this.auths,
    authorityId : 'USER_ADD',
    listeners : {
     click : this.refresh,
     scope : this
    }

   }) ]
  })
 },

 del : function() {
  var s = this.grid.getSelectionModel().getSelections();
  if (s.length == 0) {
   alert('请至少选择一个记录');
   return;
  }
  if (!confirm("确认删除?")) {
   return;
  }
 },

 refresh : function() {
  if (!confirm("确认撤销变动?")) {
   return;
  }
  this.grid.getBottomToolbar().doRefresh();
 },

 add : function() {
  var store = this.grid.getStore();
  var rows = store.getModifiedRecords();
  if (rows.length == 0) {
   alert('没有修改数据');
   return;
  }

  var baseTemplateId = "";
  var x = "";
  var sheet = "";
  var defineFlag = "";
  var defineId = "";
  var defaultValue = "";
  var valNull = "";
  var defineGroup = "";
  var genFlag = "";

  for ( var i = 0; i < rows.length; i++) {
   if (i == rows.length - 1) {
    baseTemplateId += rows[i].data["baseTemplateId"];
    x += rows[i].data["x"];
    sheet += rows[i].data["sheet"];
    defineFlag += rows[i].data["defineFlag"];
    defineId += rows[i].data["defineId"];
    // 如果默认值为“”或者为“null”则用“ ”替代
    if (rows[i].data["defaultValue"] == ""
      || rows[i].data["defaultValue"] == "null"
      || rows[i].data["defaultValue"] == null) {
     defaultValue += " ";
    } else {
     defaultValue += rows[i].data["defaultValue"];
    }
    if(rows[i].data["valNull"]==true){
     valNull += 1;
    }else{
     valNull += 0;
    }
    defineGroup += rows[i].data["defineGroup"];
    if(rows[i].data["genFlag"]==true){
     genFlag += 1;
    }else{
     genFlag += 0;
    }
   } else {
    baseTemplateId += rows[i].data["baseTemplateId"] + ",";
    x += rows[i].data["x"] + ",";
    sheet += rows[i].data["sheet"] + ",";
    defineFlag += rows[i].data["defineFlag"] + ",";
    defineId += rows[i].data["defineId"] + ",";
    if (rows[i].data["defaultValue"] == ""
      || rows[i].data["defaultValue"] == "null"
      || rows[i].data["defaultValue"] == null) {
     defaultValue += " ,";
    } else {
     defaultValue += rows[i].data["defaultValue"] + ",";
    }
    if(rows[i].data["valNull"]==true){
     valNull += 1+",";
    }else{
     valNull += 0+",";
    }
    defineGroup += rows[i].data["defineGroup"] + ",";
    if(rows[i].data["genFlag"]==true){
     genFlag += 1+",";
    }else{
     genFlag += 0+",";
    }
   }
  }
  //将选中记录进行清空,防止重复提交
  rows.length = 0;
  alert("baseTemplateIds=" + baseTemplateId + "&xs=" + x + "&sheets="
    + sheet + "&defineFlags=" + defineFlag + "&defineIds="
    + defineId + "&defaultValues=" + defaultValue + "&valNulls="
    + valNull + "&defineGroups=" + defineGroup + "&genFlags="
    + genFlag);
  // 调用增加方法
  var url = this.rootPath + "/busi/templateCfg_save.do?baseTemplateIds="
    + baseTemplateId + "&xs=" + x + "&sheets=" + sheet
    + "&defineFlags=" + defineFlag + "&defineIds=" + defineId
    + "&defaultValues=" + defaultValue + "&valNulls=" + valNull
    + "&defineGroups=" + defineGroup + "&genFlags=" + genFlag;
  var ds = util.GetMsgDs(url);
  ds.on("load", function(ds) {
   this.hideMask();
   var rs = ds.getAt(0);
   if (rs.data.status != "OK") {// 如果加载数据失败则给出错误提示
    alert("错误:" + rs.data.msg);
    return;
   }
   this.grid.getBottomToolbar().doRefresh();
  }, this);
  ds.load();
 },

 showMask : function() {
  if (!this.loadMask) {
   this.loadMask = new Ext.LoadMask(Ext.getBody(), {
    msg : "正在加载数据请稍后..."
   });
  }
  this.loadMask.show();
 },

 hideMask : function() {
  if (this.loadMask) {
   this.loadMask.hide();
  }
 }
};

我是初学者,代码有点乱。敬请原谅。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值