zoukankan      html  css  js  c++  java
  • easyui datagrid 列拖拽2

    1、拖动前

    2、拖动中

    3、拖动后

    5、代码1

    [javascript] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. $("#corp-grid").datagrid({  
    2.         title:"泥头车企业管理",  
    3.         toolbar:"#corp-grid-toolbar",  
    4.         border:false,  
    5.         fit:true,  
    6.         $(window).width()-252,  
    7.         columns:[[  
    8.                     {field:"ckb",checkbox:true},  
    9.                     {field:"corpName",title:"企业名称",200,halign:"center",align:"center",resizable:true},  
    10.                     {field:"linkedCorpName",title:"挂靠深圳企业名称",200,halign:"center",align:"center",resizable:true},  
    11.                     {field:"corpType",title:"企业类型",80,align:"center",resizable:false},  
    12.                     {field:"businessScope",title:"经营范围",80,align:"center",resizable:false},  
    13.                     {field:"effectiveDate",title:"有效日期",80,align:"center",resizable:false},  
    14.                     {field:"opePeriod",title:"营业期限",80,align:"center",resizable:false},  
    15.                     {field:"ifLocal",title:"是否本地",80,align:"center",resizable:false},  
    16.                     {field:"state",title:"有效状态",80,align:"center",resizable:false}  
    17.                 ]],  
    18.         //striped:true,  
    19.         fitColumns:true,  
    20.         //autoRowHeight:true,  
    21.         rownumbers:false,  
    22.         singleSelect:false,  
    23.         ctrlSelect:true,  
    24.         pagination:true,  
    25.         pageSize:10,  
    26.         pageList:[5,10,15,20,25,30],  
    27.         sortName:"corpId",  
    28.         sortOrder:"desc",  
    29.         url:"corp_getInfoList.action",  
    30.         method:"post",  
    31.         loadMsg:"加载数据中,请稍后",  
    32.         onDblClickRow:function(rowIndex, rowData){  
    33.             openDialog({  
    34.                 type:"view",  
    35.                 title:"泥头车企业信息查看",  
    36.                 800,  
    37.                 height:400,  
    38.                 maximizable:true,  
    39.                 href:"BaseInfo/Corp/CorpInfoView.html"  
    40.             });  
    41.         },  
    42.         onRowContextMenu:function(e, rowIndex, rowData){  
    43.             e.preventDefault();  
    44.               
    45.             $(this).datagrid("unselectAll");  
    46.               
    47.             $(this).datagrid("selectRow", rowIndex);  
    48.               
    49.             $("#corp-menu").menu("show",{  
    50.                 left:event.pageX,  
    51.                 top:event.pageY  
    52.             });  
    53.         }  
    54.     }).datagrid("columnMoving");  


    6.代码2

    [javascript] view plaincopy在CODE上查看代码片派生到我的代码片
     
      1. $.extend($.fn.datagrid.methods,{  
      2.     columnMoving:function(jq){  
      3.         return jq.each(function(){  
      4.             var grid = this;  
      5.               
      6.             var directionDiv = $("<div></div>");  
      7.               
      8.             directionDiv.hide();  
      9.               
      10.             $("body").append(directionDiv);  
      11.               
      12.             $(grid).datagrid("getPanel")  
      13.                     .find(".datagrid-header td[field]:not(td[field='ckb'])").draggable({  
      14.                 revert:true,  
      15.                 cursor:"move",  
      16.                 deltaX:10,  
      17.                 deltaY:10,  
      18.                 edge:10,  
      19.                 proxy:function(source){  
      20.                     var proxyEl = $("<div></div>");  
      21.                       
      22.                     proxyEl.addClass("dg-proxy dg-proxy-error");  
      23.                       
      24.                     proxyEl.text($(source).text());  
      25.                       
      26.                     proxyEl.appendTo($("body"));  
      27.                       
      28.                     return proxyEl;  
      29.                 }  
      30.             }).droppable({  
      31.                 accept:".datagrid-header td[field]",  
      32.                 onDragOver:function(e,source){  
      33.                     $(source).draggable("proxy").removeClass("dg-proxy-error").addClass("dg-proxy-right");  
      34.                       
      35.                     $(".dg-hide-div").hide();  
      36.                       
      37.                     var thisIndex = $(this).index();  
      38.                     var sourceIndex = $(source).index();  
      39.                       
      40.                     var className = null;  
      41.                       
      42.                     var height = null;  
      43.                       
      44.                     var thisOffset = null;  
      45.                       
      46.                     var left = null;  
      47.                     var top = null;  
      48.                       
      49.                     height = $(this).height();  
      50.                       
      51.                     if(sourceIndex > thisIndex){  
      52.                         className = "dg-move-prev";  
      53.   
      54.                         thisOffset = $(this).offset();  
      55.                           
      56.                         left = thisOffset.left;  
      57.                         top = thisOffset.top;  
      58.                     }else{  
      59.                         className = "dg-move-next";  
      60.                           
      61.                         if(thisIndex == $(this).parent().children(":last").index()){  
      62.                             thisOffset = $(this).offset();  
      63.                               
      64.                             left = thisOffset.left + $(this).width() - directionDiv.width();  
      65.                             top = thisOffset.top;  
      66.                         }else{  
      67.                             thisOffset = $(this).next().offset();  
      68.                               
      69.                             left = thisOffset.left - directionDiv.width();  
      70.                             top = thisOffset.top;  
      71.                         }  
      72.                     }  
      73.                       
      74.                     directionDiv.removeClass().addClass(className);  
      75.                     directionDiv.css({height:height, left:left, top:top});  
      76.                     directionDiv.show();  
      77.                 },  
      78.                 onDragLeave:function(e,source){  
      79.                     $(source).draggable("proxy").removeClass("dg-proxy-right").addClass("dg-proxy-error");  
      80.                       
      81.                     directionDiv.hide();  
      82.                 },  
      83.                 onDrop:function(e,source){  
      84.                     directionDiv.remove();  
      85.                       
      86.                     var thisIndex = $(this).index();  
      87.                     var sourceIndex = $(source).index();  
      88.                       
      89.                     var sourceCol = new Array();  
      90.                       
      91.                     $(source).remove();  
      92.                     $.each($(grid).datagrid("getPanel")  
      93.                                     .find(".datagrid-body tr"),function(index,obj){  
      94.                         var sourceTd = $(obj).children("td:eq(" + sourceIndex + ")");  
      95.                           
      96.                         sourceCol.push(sourceTd);  
      97.                           
      98.                         sourceTd.remove();  
      99.                     });  
      100.                       
      101.                     var prev = sourceIndex > thisIndex;  
      102.                       
      103.                     thisIndex = $(this).index();  
      104.                       
      105.                     if(prev){  
      106.                         $(this).before($(source));  
      107.                     }else{  
      108.                         $(this).after($(source));  
      109.                     }  
      110.                       
      111.                     $.each($(grid).datagrid("getPanel")  
      112.                                     .find(".datagrid-body tr"),function(index,obj){  
      113.                         var thisTd = $(obj).children("td:eq(" + thisIndex + ")");  
      114.                           
      115.                         if(prev){  
      116.                             thisTd.before(sourceCol[index]);  
      117.                         }else{  
      118.                             thisTd.after(sourceCol[index]);  
      119.                         }  
      120.                     });  
      121.                       
      122.                     $(grid).datagrid("columnMoving").datagrid("columnHiding");  
      123.                 }  
      124.             });  
      125.         });  
      126.     }  
      127. });  
  • 相关阅读:
    input 控制输入非负数
    查看web项目中的.class文件的路径
    web(获取路径的方法)
    javascript从入门到精通(三)
    javascript从入门到精通(二)
    javascript从入门到精通(一)
    jquery从入门到精通(一)
    background-sizi (转)
    background-position (转)
    html,css命名规范 (转)
  • 原文地址:https://www.cnblogs.com/lenther2002/p/4672074.html
Copyright © 2011-2022 走看看