免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2853 | 回复: 0
打印 上一主题 下一主题

datagrid扩展editor [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-17 16:17 |只看该作者 |倒序浏览
datagrid扩展editor





easyui1.2.4支持了数据编辑功能,但提供的东西有限,所以需要自己进行扩展。下面是扩展一个datetimebox的编辑器。

Js代码
  1. 1.$.extend($.fn.datagrid.defaults.editors, {   
  2. 2.     datetimebox: {//datetimebox就是你要自定义editor的名称   
  3. 3.         init: function(container, options){   
  4. 4.             var input = $('<input class="easyuidatetimebox">').appendTo(container);   
  5. 5.             return input.datetimebox({   
  6. 6.                 formatter:function(date){   
  7. 7.                     return new Date(date).format("yyyy-MM-dd hh:mm:ss");   
  8. 8.                 }   
  9. 9.             });   
  10. 10.         },   
  11. 11.         getValue: function(target){   
  12. 12.             return $(target).parent().find('input.combo-value').val();   
  13. 13.         },   
  14. 14.         setValue: function(target, value){   
  15. 15.             $(target).datetimebox("setValue",value);   
  16. 16.         },   
  17. 17.        resize: function(target, width){   
  18. 18.             var input = $(target);   
  19. 19.             if ($.boxModel == true){   
  20. 20.                 input.width(width - (input.outerWidth() - input.width()));   
  21. 21.             } else {   
  22. 22.                 input.width(width);   
  23. 23.             }   
  24. 24.         }   
  25. 25.     }   
  26. 26.  
  27. 27. });  
  28. $.extend($.fn.datagrid.defaults.editors, {
  29.      datetimebox: {//datetimebox就是你要自定义editor的名称
  30.          init: function(container, options){
  31.              var input = $('<input class="easyuidatetimebox">').appendTo(container);
  32.              return input.datetimebox({
  33.                  formatter:function(date){
  34.                      return new Date(date).format("yyyy-MM-dd hh:mm:ss");
  35.                  }
  36.              });
  37.          },
  38.          getValue: function(target){
  39.              return $(target).parent().find('input.combo-value').val();
  40.          },
  41.          setValue: function(target, value){
  42.              $(target).datetimebox("setValue",value);
  43.          },
  44.         resize: function(target, width){
  45.              var input = $(target);
  46.              if ($.boxModel == true){
  47.                  input.width(width - (input.outerWidth() - input.width()));
  48.              } else {
  49.                  input.width(width);
  50.              }
  51.          }
  52.      }

  53. });
复制代码
自己测试过的代码

Js代码
  1. 1.$.extend($.fn.datagrid.defaults.editors, {      
  2. 2.            datetimebox :{      
  3. 3.                init: function(container, options){      
  4. 4.                    var input = $('<input class="easyuidatetimebox">').appendTo(container);   
  5. 5.                     return input.datetimebox();     
  6. 6.                },      
  7. 7.                getValue: function(target){      
  8. 8.                    return $(target).datetimebox("getValue");      
  9. 9.                },      
  10. 10.                setValue: function(target, value){      
  11. 11.                    $(target).datetimebox("setValue",value);   
  12. 12.                },      
  13. 13.                resize: function(target, width){      
  14. 14.                    var input = $(target);      
  15. 15.                    if ($.boxModel == true){      
  16. 16.                        input.width(width - (input.outerWidth() - input.width()));      
  17. 17.                    } else {      
  18. 18.                        input.width(width);      
  19. 19.                    }      
  20. 20.                }      
  21. 21.            }      
  22. 22.        });   
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP