angualr项目table拖拽列宽效果

首先要有一个table的html列表 我就不上了,因为加载有异步的问题,所以我把js代码放到一个封装函数里面,表格加载出来之后调用函数,这个表格的dom就能找到了。下面是封装的js代码

  //拖拽调整列宽
        $rootScope.searchTable= function(){
          var tTD; //用来存储当前更改宽度的Table Cell,避免快速移动鼠标的问题
            var table = document.getElementsByClassName(‘table‘);
            console.log(table);
            for (j = 0; j < table[0].rows[0].cells.length; j++) {
                table[0].rows[0].cells[j].onmousedown = function () {
        //记录单元格
                    tTD = this;
                    if (event.offsetX > tTD.offsetWidth - 10) {
                        tTD.mouseDown = true;
                        tTD.oldX = event.x;
                        tTD.oldWidth = tTD.offsetWidth;
                    }
        //记录Table宽度
        //table = tTD; while (table.tagName != ‘TABLE‘) table = table.parentElement;
        //tTD.tableWidth = table.offsetWidth;
                };
                table[0].rows[0].cells[j].onmouseup = function () {
        //结束宽度调整
                    if (tTD == undefined) tTD = this;
                    tTD.mouseDown = false;
                    tTD.style.cursor = ‘default‘;
                };
                table[0].rows[0].cells[j].onmousemove = function () {
        //更改鼠标样式
                    if (event.offsetX > this.offsetWidth - 10)
                        this.style.cursor = ‘col-resize‘;
                    else
                        this.style.cursor = ‘default‘;
        //取出暂存的Table Cell
                    if (tTD == undefined) tTD = this;
        //调整宽度
                    if (tTD.mouseDown != null && tTD.mouseDown == true) {
                        tTD.style.cursor = ‘default‘;
                        if (tTD.oldWidth + (event.x - tTD.oldX) > 0)
                            tTD.width = tTD.oldWidth + (event.x - tTD.oldX);
        //调整列宽
                        tTD.style.width = tTD.width;
                        tTD.style.cursor = ‘col-resize‘;
        //调整该列中的每个Cell
                        table[0] = tTD;
                        while (table[0].tagName != ‘TABLE‘) table = table[0].parentElement;
                        for (j = 0; j < table[0].rows.length; j++) {
                            table[0].rows[j].cells[tTD.cellIndex].width = tTD.width;
                        }
        //调整整个表
        //table.width = tTD.tableWidth + (tTD.offsetWidth – tTD.oldWidth);
        //table.style.width = table.width;
                    }
                };
            }

        }

//下面是加载数据 调用函数的方法
  //列表搜索控制
        $rootScope.pagessizes = [10,20,50,100,500];
        $rootScope.getApiListFn = function (clearPage) {
          $rootScope.searchTable();
          // console.log(clearPage);
            $rootScope.allCheckState=false;

            $rootScope.apiState.apiLoading = true;
            // console.log($rootScope.posts);
            var sendData = angular.copy($rootScope.posts);
            sendData.pageNum = clearPage ? 1 : sendData.pageNum;
            // if (clearPage==undefined) {
            //   sendData.pageNum=1;
            // }
            // if (sendData.starttime) {
            //     var starttime = $filter("date")(sendData.starttime, ‘yyyy-MM-dd‘) + " 00:00:00";
            //     sendData.starttime = new Date(starttime).getTime();
            // }
            // if (sendData.orderTime) {
            //     sendData.orderTime = new Date(sendData.orderTime).getTime();
            // }
            // if (sendData.endtime) {
            //     var endtime = $filter("date")(sendData.endtime, ‘yyyy-MM-dd‘) + " 23:59:59";
            //     sendData.endtime = new Date(endtime).getTime();
            // }
            // $rootScope.pages={};
            // sendData.pageSize = 10; //每页多少个
            $http.post($rootScope.searchApi,sendData,$rootScope.postCfg).success(function(data){
              $rootScope.apiState.apiLoading = false;
              $rootScope.apiResultList=data.model.list;
              // $rootScope.posts = {};
              // $rootScope.postss = data.model;
              if (!data) {
                      data.model = {
                          list: [],
                          total: 0
                      };
                  }
              $rootScope.pages = data.model;
              // console.log(pages);
              // $rootScope.pages = data.model.navigatepageNums;
              $rootScope.pages.pageTotal =true;
              $rootScope.dataTotal = data.model.total;
              console.log($rootScope.pages);
            });
            // api($rootScope.searchApi, {
            //     data: sendData
            // }).then(function (data) {
            //     $rootScope.apiState.apiLoading = false;
            //     if (!data) {
            //         data = {
            //             list: [],
            //             total: 0
            //         };
            //     }
            //     $rootScope.apiResultList = data.list || data.commodityList|| data || [];
            //     // console.log($rootScope.apiResultList)
            //     var pages = Paging(sendData, (data.total || data.countNumber));
            //     $rootScope.pages = pages.pages;
            //     $rootScope.pageTotal = pages.pageTotal;
            //     $rootScope.dataTotal = data.total;
            // });
        };
        $rootScope.pageGo = function (index) {
            $rootScope.posts.pageNum = index;
            $rootScope.getApiListFn();
        };

        $rootScope.value="1";
        $rootScope.resetPagesize=function(value){
          // console.log(value);
          if (value=="0") {
            $rootScope.posts.pageSize=10;
          }
          if (value=="1") {
            $rootScope.posts.pageSize=20;
          }
          if (value=="2") {
            $rootScope.posts.pageSize=50;
          }
          if (value=="3") {
            $rootScope.posts.pageSize=100;
          }
          if (value=="4") {
            $rootScope.posts.pageSize=500;
          }
          console.log($rootScope.posts);
          // console.log($event);
          // console.log($parent.Carts.CartItemList[$index].Selected);
          // $rootScope.posts.pageSize = $rootScope.posts.pageSize;
          $rootScope.getApiListFn();
        }

        $rootScope.search = function () {
          // console.log(value);
          // console.log($rootScope.posts);
          // console.log(data);
            $rootScope.getApiListFn();
        };
        $rootScope.resetAll = function () {
            $rootScope.posts = {};
            $rootScope.posts.pageNum=1;
            $rootScope.posts.pageSize=20;
            $rootScope.getApiListFn();
            // $state.reload();
        };
        // $scope.resetLis="全部";

        // $(‘icon‘).on("click",function(){
        //   $(‘icon‘).toggleClass(‘icons‘)
        // })

        // $http.post("http://10.224.171.24:8089/cps-cas-web/helper/validateImg",{
        //   pageNum:1,
      	// 	pageSize:20
        // },postCfg).success(function(data){
        //   $scope.imgass = data;
      	// 	console.log(data);
      	// });

  拖拽效果差不多就这样

				
时间: 2024-08-07 00:18:47

angualr项目table拖拽列宽效果的相关文章

Blend Grid行列拖拽控制宽高

原文:Blend Grid行列拖拽控制宽高 看效果 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="212*"/> <ColumnDefinition Width="9*"/> <ColumnDefinition Width="296*"/> </Grid.ColumnDefinitions> <Grid

JS打造的拖拽翻页效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

Js使用面向对象和面向过程的方法实现拖拽物体的效果

1.面向过程的拖拽实现代码: <!DOCTYPE html> <html> <head> <title>drag Div</title> <style type="text/css"> #div1{width: 100px;height: 100px;background: red;position: absolute;} </style> <script type="text/java

实现一个宽和高都是100像素的div可以用鼠标拖拽移动的效果

html,body{ width:100%;height:100%;margin:0px;padding:0px; } #box{ width:100px;height:100px;background:pink;position:absolute; } div id="box"></div> window.onload = function(){ var box = document.getElementById('box'); box.onmousedown =

BezierDemo源码解析-实现qq消息气泡拖拽消失的效果

这篇文章中我们比较了DraggableFlagView和BezierDemo两个项目的区别,提到将对其中一个做源码分析,那么我们就来分析BezierDemo的源码吧,因为这个项目的源码最简单,可以更直接的去分析核心的东西.但是效果还是DraggableFlagView好些.我尽量讲的详细些,满足更多的初学者.这篇文章主要分析拉伸效果的实现. 源码结构 BezierDemo只有两个java文件 其中MainActivity.java是程序界面,而BezierView.java是实现了粘连拉伸效果的

针对后台列表table拖拽比较实用的jquery拖动排序

<!DOCTYPE html> <html lang="en"> <head>  <meta charset="UTF-8">  <title>jqueryUI拖动</title> </head> <script src="js/jquery-1.11.0.min.js"></script> <script src="js/

[ActionScript 3.0] AS3 拖拽混动效果之一

package { import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.net.URLRequest; /** * @author Frost.Yen * @E-mail [email protected] * @create 2015-11-17 上午10:20:30 * */ [SWF(

jquery实现行列的单向固定和列的拖拽

其实这些功能在PL/SQL Dev中都有实现,在页面中还是蛮常见的. 我实现列的单向固定的原理:将需要单向固定的列放在一个<table>标签中,而整体的数据放在另一个<table>标签中. 列的拖拽:使用onstartdrag.ondragover.drop事件 1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>table拖拽与行列固定</title> 5 <script sr

Android基础控件——RecyclerView实现拖拽排序侧滑删除效果

RecyclerView实现拖拽排序侧滑删除效果 事先说明: RecyclerView是ListView的升级版,使用起来比ListView更规范,而且功能和动画可以自己添加,极容易扩展,同样也继承了ListView复用convertView和ViewHolder的优点.   思路分析: 1.导包.在布局中使用RecyclerView 2.需要一个JavaBean用来存储展示信息 3.需要一个填充RecyclerView的布局文件 4.在代码中找到RecyclerView,并为其绑定Adapte