zoukankan      html  css  js  c++  java
  • 扩展easyui datagrid的两个方法.动态添加和删除toolbar的项

     1 $.extend($.fn.datagrid.methods, {  
     2     addToolbarItem: function(jq, items){  
     3         return jq.each(function(){  
     4             var toolbar = $(this).parent().prev("div.datagrid-toolbar");
     5             for(var i = 0;i<items.length;i++){
     6                 var item = items[i];
     7                 if(item === "-"){
     8                     toolbar.append('<div class="datagrid-btn-separator"></div>');
     9                 }else{
    10                     var btn=$("<a href=\"javascript:void(0)\"></a>");
    11                     btn[0].onclick=eval(item.handler||function(){});
    12                     btn.css("float","left").appendTo(toolbar).linkbutton($.extend({},item,{plain:true}));
    13                 }
    14             }
    15             toolbar = null;
    16         });  
    17     },
    18     removeToolbarItem: function(jq, param){  
    19         return jq.each(function(){  
    20             var btns = $(this).parent().prev("div.datagrid-toolbar").children("a");
    21             var cbtn = null;
    22             if(typeof param == "number"){
    23                 cbtn = btns.eq(param);
    24             }else if(typeof param == "string"){
    25                 var text = null;
    26                 btns.each(function(){
    27                     text = $(this).data().linkbutton.options.text;
    28                     if(text == param){
    29                         cbtn = $(this);
    30                         text = null;
    31                         return;
    32                     }
    33                 });
    34             } 
    35             if(cbtn){
    36                 var prev = cbtn.prev()[0];
    37                 var next = cbtn.next()[0];
    38                 if(prev && next && prev.nodeName == "DIV" && prev.nodeName == next.nodeName){
    39                     $(prev).remove();
    40                 }else if(next && next.nodeName == "DIV"){
    41                     $(next).remove();
    42                 }else if(prev && prev.nodeName == "DIV"){
    43                     $(prev).remove();
    44                 }
    45                 cbtn.remove();    
    46                 cbtn= null;
    47             }                        
    48         });  
    49     }                 
    50 });
    1 $('#tt').datagrid("addToolbarItem",[{"text":"xxx"},"-",{"text":"xxxsss","iconCls":"icon-ok"}])
    1 $('#tt').datagrid("removeToolbarItem","GetChanges")//根据btn的text删除
    1 $('#tt').datagrid("removeToolbarItem",0)//根据下标删除
  • 相关阅读:
    要打印
    1月21日
    弹出层layer的使用
    Python学习笔记文件操作list列表操作
    Python学习笔记控制流之布尔值
    Python学习笔记控制流之操作运算符
    Python学习笔记字符串
    Python学习笔记list_to_str列表转字符串
    DropDownList 下拉无限极分类代码
    Jquery 基础教程测试
  • 原文地址:https://www.cnblogs.com/XiaoGer/p/2537047.html
Copyright © 2011-2022 走看看