npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

drag-cell-resize

v1.0.4

Published

drag cell resize table col

Downloads

9

Readme

dragCellResize

拖拽表格列宽,支持Vue指令

安装

npm & yarn

npm install drag-cell-resize

yarn add drag-cell-resize

cdn

umd版本(包含指令和DragCellResize类):

<script src="https://unpkg.com/drag-cell-resize/dist/index.min.js"></script>

var版本(仅包含DragCellResize类):

<script src="https://unpkg.com/drag-cell-resize/dist/index.var.js"></script>

使用方式

  • 在Vue中使用

Vue Demo

1.作为指令使用

import Vue from 'vue'
import directive from 'drag-cell-resize'
Vue.use(directive)
<template>
    <table v-drag-cell-resize>...</table>
</template>

指令不仅仅可以绑定在table中,只要其包含table表格都可以绑定,例如:

<template>
    <div v-drag-cell-resize>
      <table>...</table>
    </div>
</template>

2.直接调用DragCellResize类

<template>
    <table refs="table">...</table>
</template>
<script >
    import {DragCellResize} from 'drag-cell-resize'
   export default {
       mounted(){
          new DragCellResize(this.$refs['table'])
       }
   }   
</script>
  • 不使用Vue的情况下

<html>
<body>
    <table id="table">...</table>
</body>
</html>
<script src="https://unpkg.com/drag-cell-resize/dist/index.var.js"></script>
<script >
    // index.var.js中仅仅只有DragCellResize类
    new DragCellResize(document.getElementById('table'))
</script>

DragCellResize类

指令本质上就是在bind时实例化了DragCellResize类.

注:在使用v-drag-cell-resize的时候,由于某些情况下thead或者整个table都还未被渲染(例如使用了v-if),指令无法在bindinsert钩子上获取到dom对象.所以如果在bind阶段未找到dom的话,指令会尝试在update钩子上获取表格的dom对象及绑定事件. 尽管用到了update钩子,会多次触发指令绑定,但是外部用了Map来缓存domDragCellResize的关系,.所以DragCellResize一旦被实例化后不会便不会再重复实例化和绑定事件.

构造参数 new DragCellResize(el,callbakc,isCustom)

| 参数 | 释义 | 是否必填 | | :-----| :----: | :----: | | el | 欲绑定的Dom元素,不限于表格,只要包含表格即可 | 是 | | callback | 完成拖拽后的回调函数/自定义处理拖拽。可在拖拽后执行某些操作 | 否(如果isCustom为true,callback必传) | | isCustom | 是否自定义处理拖拽操作,如果为true,拖拽的后不会设置列宽,交由callback处理 | 否 |

Demo

注意事项:

由于td会动态分配整个table的宽度,进而导致实际设置的width大小不是td的真实宽度.就会导致拖拽的宽度不是实际得到的大小.例如,明明拖拽后总宽度是100px,实际上表现的会超过100px.无法对齐到虚线处

所以需要对表格的th,td增加css样式.设置其box-sizingborder-box