Grid常见操作

 grid = $("#grid").data("kendoGrid"); //获取kendoGrid对象
   for (var i = 0; i < grid.columns.length; i++) { //遍历所有字段
                if (grid.columns[i].field != null) {
                    var columnInfo = {};
                    columnInfo["name"] = grid.columns[i].field; //获取字段name
                    columnInfo["title"] = grid.columns[i].title; //获取字段实际显示标题
                    columnInfo["width"] = grid.columns[i].width; //获取字段显示宽度
       editable: false,//grid不可编辑
        autoBind: false,//grid不自动加载
//grid某列不可编辑
 fields: {
                    customerCode:{
                        editable:false,
                        type:"string",
                    },
           }
//grid某个字段为必输
 fields: {
   description:{
                        validation: {
                            required: true
                        },
                    },
        }
 /*隐藏列customerId*/
    var grid = $("#grid").data("kendoGrid");
    grid.hideColumn("customerId");
//grid点击事件
  $(grid).on("click", "td", function (e) {
      var rowIndex = $(this).parent().index();
      var contactData = $("#grid").data("kendoGrid").dataSource.data();
      otviewModel.model.set("trxSummaryId",contactData[rowIndex].trxSummaryId);//获取所点击字段
      $('#outstorageTrxGrid').data('kendoGrid').dataSource.page(1);//grid刷新
  })
//grid字段改变事件,但里面内容改变时,触发change
{
                field: "price",
                title: '<@spring.message "product.price"/>',
                width: 120,
                editor: function (container, options) {
                    $('<input name = "' + options.field
                        + '"/>').appendTo(container).kendoNumericTextBox({
                        min: 0,
                        change: function () {
                            if(options.model.get("manDay")>0&options.model.get("price")>0) {
                                options.model.set('totalPrice', options.model.get("manDay")*options.model.get("price"));
                            }else {
                                options.model.set('totalPrice',0);
                            }
                        }
                    });
                },
            },
<script src="${base.contextPath}/common/code?orgTypeData=SYS.UNIT_TYPE"
        type="text/javascript">//”代码维护“配置的信息
//grid字段设置为下拉框
 {
                field: "orgType",
                title: '<@spring.message "ora20796orgaccess.orgtype"/>',
                width: 120,
                template: function (dataItem) {
                    var v = dataItem.orgType;
                    $.each(orgTypeData, function (i, n) {
                        if ((n.value || '').toLowerCase() == (v || '').toLowerCase()) {
                            v = n.meaning;
                            return v;
                        }
                    });
                    return v;
                },
                editor: function (container, options) {
                    $('<input name = "' + options.field
                        + '"/>').appendTo(container).kendoDropDownList({
                        dataTextField: "meaning",
                        dataValueField: "value",
                        dataSource: orgTypeData,
                        change: function () {
// 在change事件中设置lovCode的值,并清空lov表单元素的值
                            options.model.set('orgType', this.value());
                            //清空重置组织名称字段
                            options.model.set('orgId',null);
                            options.model.set('orgName', null);
                        }
                    });
                }
            },
//grid字段设置为日期选择器
 {
                field: "startDate",
                title: '<@spring.message "ora20796orgaccess.startdate"/>',
                width: 120,
                format: "{0:yyyy-MM-dd}",
                editor: function (container, options) {
                    var end = options.model.endDate;
                    var opts = {
                        format: "yyyy-MM-dd"
                    };
                    if (end) {
                        opts.max = end;
                    }
                    $('<input name="' + options.field + '"/>')
                        .appendTo(container)
                        .kendoDatePicker(opts);
                },
            },
            {
                field: "endDate",
                title: '<@spring.message "ora20796orgaccess.enddate"/>',
                width: 120,
                format: "{0:yyyy-MM-dd}",
                editor: function(container, options){
                    var start = options.model.startDate;
                    var opts={
                        format:"yyyy-MM-dd"
                    };
                    //设置min属性 限制最小的可选日期
                    if(start){
                        opts.min=start;
                    }
                    $('<input name="' + options.field + '"/>')
                        .appendTo(container)
                        .kendoDatePicker(opts);
                },
            },

//grid字段设置为复选框
   fields: {                    
                    replaceDepFlag: {defaultValue: 'N', type: 'boolean', checkedValue: 'Y', uncheckedValue: 'N'},
                    enableFlag: {defaultValue: 'Y', type: 'boolean', checkedValue: 'Y', uncheckedValue: 'N'}
                }



   {
                field: "replaceDepFlag",
                title: '<@spring.message "departmentlookup.replacedepflag"/>',
                width: 55,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "text-align:center"
                },
                sortable: false,
            },
    
            {
                field: "enableFlag",
                title: '<@spring.message "departmentlookup.enableFlag"/>',
                width: 55,
                headerAttributes: {
                    "class": "table-header-cell",
                    style: "text-align: center"
                },
                attributes: {
                    style: "text-align:center"
                },
                sortable: false,
            },
13265172-4b076cc9d976da36.png
image.png
//grid字段设置为LOV
{
              field: "orgId",
              title: '<@spring.message "ora20796orgaccess.orgid"/>',
              width: 120,
              template: function (dataItem) {
                  return dataItem['orgName'] || ''; /* 数据列默认显示值 */
              },
              editor: function (container, options) {
                  $('<input name="'+ options.field +'" />').appendTo(container)
                      .kendoLov($.extend(<@lov "ORA_20796_ORG_NAME" />, {
                      query: function (e) {
                          e.param['enableFlag'] = 'Y';
                          e.param['unitType'] = options.model.get("orgType");
                      },
                      select: function (e) {
                          // 将选择后的属性更新到数据模型中以保存
                          options.model.set('orgId', e.item.unitId);
                      },
                      textField: 'orgName', /* 编辑器显示的值 */
                      model: options.model
                  }));
              }
          },
          {
              field: "roleId",
              title: '<@spring.message "ora20796orgaccess.roleid"/>',
              width: 120,
              template: function (dataItem) {
                  return dataItem['roleName'] || ''; /* 数据列默认显示值 */
              },
              editor: function (container, options) {
                  $('<input name="'+ options.field +'" />').appendTo(container)
                      .kendoLov($.extend(<@lov "ORA_20796_ORG_ROLE" />, {
                      query: function (e) {
                          e.param['enableFlag'] = 'Y';
                          options.model.set('userId',null);
                          options.model.set('userName', null);
                      },
                      select: function (e) {
                          // 将选择后的属性更新到数据模型中以保存
                          options.model.set('roleId', e.item.roleId);
                      },
                      textField: 'roleName', /* 编辑器显示的值 */
                      model: options.model
                  }));
              }

          },
          {
              field: "userId",
              title: '<@spring.message "ora20796orgaccess.userid"/>',
              width: 120,
              template: function (dataItem) {
                  return dataItem['userName'] || ''; /* 数据列默认显示值 */
              },
              editor: function (container, options) {
                  $('<input name="'+ options.field +'" />').appendTo(container)
                      .kendoLov($.extend(<@lov "ORA_20796_ORG_USER" />, {
                      query: function (e) {
                          e.param['enableFlag'] = 'Y';
                          e.param['userType'] = options.model.get("roleId");
                      },
                      select: function (e) {
                          // 将选择后的属性更新到数据模型中以保存
                          options.model.set('userId', e.item.userId);
                      },
                      textField: 'userName', /* 编辑器显示的值 */
                      model: options.model
                  }));
              }
          },
//grid 字段获取接口数据
/*国家*/
            {
                field: "addressCountry",
                title: '<@spring.message "customercontact.addresscountry"/>',
                width: 120,
                editor: function (container, options) {
                    $('<input name = "' + options.field
                        + '"/>').appendTo(container).kendoDropDownList({
                        dataTextField: "addressName",
                        dataValueField: "addressId",
                        valuePrimitive: true,
                        dataSource: {
                            transport: {
                                read: '/hcrm/base/customer/getAddressByType?type=COUNTRY&parentAddressId=0',
                                dateType: 'json',
                                contentType: 'application/json'
                            }
                        },
                        change: function () {
                            // 在change事件中设置lovCode的值,并清空lov表单元素的值
                            options.model.set('addressCountry', this.value());
                        }
                    });
                },
                template: function (dataItem) {
                    var value = dataItem.addressCountry;
                    var name = "";
                    $.ajax({
                        url: '/hcrm/base/customer/getAddressByType?type=COUNTRY&parentAddressId=0',
                        type: 'POST',
                        dataType: "json",
                        contentType: "application/json",
                        async: false,
                        success: function (result) {
                            for (var i in result) {
                                var id = result[i].addressId;
                                if (value == id) {
                                    name = result[i].addressName;
                                    return;
                                }
                            }
                        }
                    });
                    return name;
                }
            },

待续...

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值