kendoUI下拉框

来源:互联网 发布:青岛易亚网络骗局 编辑:程序博客网 时间:2024/06/05 19:59

kendoUI下拉框之固定值选项:
在$("#demo_grid").kendoGrid的columns中设置属性“isEnable”是固定值为“Yes”/“No”的下拉列表:
    {
field: "isEnable", 
    /*title: "<fmt:messagekey="p.message.isEnable"/>",此处标题设置国际化*/
title: "isEnable",
    attributes: {style: "font-size: 15px"},
    template: function(dataItem) {
    var value = dataItem.isEnable;
    if(value === "Y"){
    return "Yes";
    }else if(value === "N"){
    return "No";
    }else{
    return "";
    }
    },
    editor: function(container,options){
    $('<input name="'+options.field+'"/>')
    .appendTo(container)
    .kendoDropDownList({
    dataTextField: "is_enableText",
    dataValueField: "is_enableValue",
    valuePrimitive: true,
    dataSource: [
                   {is_enableText: "Yes", is_enableValue: "Y"},
                   {is_enableText: "No", is_enableValue: "N" }
               ]
    });
    }
    }


kendoUI下拉框之获取值选项及如何设置kendoUI下拉框中的默认值:
同样的,在$("#demo_grid").kendoGrid的columns中设置属性“Rate”的值来自后台url"/getRate"(此链接返回的是一个对象列表,以对象的形式将属性“Rate”值封装起来传输过来)中数据的下拉列表:
{
  field: "Rate", title: "rate", attributes: {style: "font-size: 15px"}, width:"115px", template: function(dataItem) {
    if(dataItem != null){
    return dataItem.tier1RatePlan;
    }
    },
    editor: function(container,options){
    $('<input name="'+options.field+'"/>')
    .appendTo(container)
    .kendoDropDownList({
    dataTextField: "ratePlan",
    dataValueField: "ratePlan",//ratePlan:对应此“/getRate”返回对象的一个属性名
    valuePrimitive: true,
    autoBind:true,
    dataSource: {
            transport: {
                   read: "/getPlan",
                   dataType: "json"
                       }
               },
                  //添加的时候下拉表默认选择一个
                    dataBound: function(e){
                  if (this.select() === -1) { //check whether any item is selected
                      this.select(0);
                      this.trigger("change");//真实有效的获取到这个值(而非仅仅显示出来)
                    }
                  }   
    });
     }
    },


在schema之前可通过添加requestStart或requestEnd来控制在执行每个operation("read"/"create"/"update"/"destroy"...)之前或之后做点什么。例如,在执行非read操作结束时,demoGrid中的数据进行一次read操作即每进行一次操作之后都read重新读取一遍(等于是刷新一遍):
   requestEnd: function(e){
if(e.type != "read"){
     demoGrid.data("kendoGrid").dataSource.read(); 

},  
原创粉丝点击