sindu12jun / table-dragger Goto Github PK
View Code? Open in Web Editor NEWTurn your old table to drag-and-drop table with columns and rows sorting like magic!
Home Page: https://sindu12jun.github.io/table-dragger/
License: MIT License
Turn your old table to drag-and-drop table with columns and rows sorting like magic!
Home Page: https://sindu12jun.github.io/table-dragger/
License: MIT License
Very nice library!
I have a table where the first row and first column are headers and need to be fixed. I am close, but could only do one or the other based on whether I apply column or row mode first. See https://output.jsbin.com/papohan/1. I also tried free mode, however, it did not produce the desired results. Any thoughts?
Thanks
Thanks for an awesome plugin.
Please add supported browsers to the readme.
When I try to drag in a table that is in a div that is display:grid, it is impossible to drag elements which are not visible when scrolled all the way to the top. As soon as the with drag even first, suddenly the entire table appears to be scrolled back up to the top (although the scrollbar remains in the unscrolled position), and it is impossible to scroll down past the first screen.
id "test" is what I am putting the table-dragger on using:
var dragger = tableDragger(tab, { mode:"row", onlyBody:true, animation: 300 })
Here is an example of the HTML:
<div style="display: grid; grid-template-columns: 100vw; grid-template-rows: 100vh; overflow: hidden;"><div style="display: grid; grid-template-columns: 25% 75%; grid-template-rows: 100%; overflow: hidden;"><div style="overflow: scroll;" class=""><table id="test" border="1" tabindex="1" class="sindu_origin_table" style="border-collapse: collapse;"><tbody><tr><td class="sindu_handle">TEST0</td></tr><tr><td class="sindu_handle">TEST1</td></tr><tr><td class="sindu_handle">TEST22</td></tr><tr><td class="sindu_handle">TEST23</td></tr><tr><td class="sindu_handle">TEST2</td></tr><tr><td class="sindu_handle">TEST3</td></tr><tr><td class="sindu_handle">TEST4</td></tr><tr><td class="sindu_handle">TEST5</td></tr><tr><td class="sindu_handle">TEST6</td></tr><tr><td class="sindu_handle">TEST7</td></tr><tr><td class="sindu_handle">TEST8</td></tr><tr><td class="sindu_handle">TEST9</td></tr><tr><td class="sindu_handle">TEST10</td></tr><tr><td class="sindu_handle">TEST11</td></tr><tr><td class="sindu_handle">TEST12</td></tr><tr><td class="sindu_handle">TEST13</td></tr><tr><td class="sindu_handle">TEST14</td></tr><tr><td class="sindu_handle">TEST15</td></tr><tr><td class="sindu_handle">TEST16</td></tr><tr><td class="sindu_handle">TEST17</td></tr><tr><td class="sindu_handle">TEST18</td></tr><tr><td class="sindu_handle">TEST19</td></tr><tr><td class="sindu_handle">TEST20</td></tr><tr><td class="sindu_handle">TEST21</td></tr><tr><td class="sindu_handle">TEST24</td></tr><tr><td class="sindu_handle">TEST25</td></tr><tr><td class="sindu_handle">TEST26</td></tr><tr><td class="sindu_handle">TEST27</td></tr><tr><td class="sindu_handle">TEST28</td></tr><tr><td class="sindu_handle">TEST29</td></tr><tr><td class="sindu_handle">TEST30</td></tr><tr><td class="sindu_handle">TEST31</td></tr><tr><td class="sindu_handle">TEST32</td></tr><tr><td class="sindu_handle">TEST33</td></tr><tr><td class="sindu_handle">TEST34</td></tr><tr><td class="sindu_handle">TEST35</td></tr><tr><td class="sindu_handle">TEST36</td></tr><tr><td class="sindu_handle">TEST37</td></tr><tr><td class="sindu_handle">TEST38</td></tr><tr><td class="sindu_handle">TEST39</td></tr><tr><td class="sindu_handle">TEST40</td></tr><tr><td class="sindu_handle">TEST41</td></tr><tr><td class="sindu_handle">TEST42</td></tr><tr><td class="sindu_handle">TEST43</td></tr><tr><td class="sindu_handle">TEST44</td></tr><tr><td class="sindu_handle">TEST45</td></tr><tr><td class="sindu_handle">TEST46</td></tr><tr><td class="sindu_handle">TEST47</td></tr><tr><td class="sindu_handle">TEST48</td></tr><tr><td class="sindu_handle">TEST49</td></tr></tbody></table></div></div></div>
I took three screenshots. First, before I started to drag. I am getting ready to drag TEST23:
This is is right after the drag started. Suddenly TEST23 is up between TEST1 and TEST2 at the top, despite the scrollbar being unchanged:
Next, I had dragged slightly to the right and down. A ghost of TEST23 can be seen down where it's supposed to be. However, if I drop it does not wind up where the ghost is, instead it gets dropped wherever the copy in the table is. In the screen shot below if I drop at this point it winds up between TEST1 and TEST2. But TEST30 is the lowest visible element and the lowest element I can drop it below - it is impossible to arrange it lower than that. Depending on where the element initially was, for elements far enough down the list (e.g. after TEST30) it is impossible to move them any lower, so for instance it's impossible to move any element to the bottom in any number of moves, because once it gets past TEST30 it can't go any further.
This information does not help to understand witch row was moved console.log(
drop ${el.nodeName} from ${from} ${mode} to ${to} ${mode})
So how to update sorting on server side?
Hello.
NPM contains version 1.0.3. But current development branch has a little bit different files structure. I'm wondering, can I rely on the same interface and how soon the new version will be published?
Thanks.
Hi ,
I want to code my own simple table drag cause some reason,And I have read all of this project code, But I find it's hard for me to understand code design.Do you have any other docs which can help me to understand your code and design better?
tks
When dragging a column the visual effect stops immedialty, and I have to release the mouse button, to get visual feedback again, and then I have to click to drop the column table !
Here is a jsfiddle with an example https://jsfiddle.net/kjaugcqk/
I don't know, may be it's an issue with firefox and not your plugin ??
My table is displaying a tree layout (child nodes are indented in one of the columns). It would be nice if there was some way to specify ranges of rows that belong together, such that if the first row in a group is dragged, all rows in the group are dragged together. The groups could not be exclusive, because for instance if I have several levels of nesting, if I drag the top level it should also drag all the levels under it, but if I drag the second level it shouldn't drag the top level above it, just itself and the levels under it.
table-dragger:"^2.0.1"
vue:"^2.5.7"
nodejs:"10.15.3"
npm:"6.10.0"
demo.vue
...
import tableDragger from "table-dragger"
...
var el = document.getElementsByTagName('table')[0];
console.log(tableDragger); // ---> {}
var dragger = tableDragger(el, {
mode: 'row',
dragHandler: '.handle',
onlyBody: true,
animation: 300
});
// Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_table_dragger___default(...) is not a function at
I got multiple tables that i pass to the view dynamically, so how can i initialize it using a class selector?
I updated table-dragger in an AngularJS application to v2.0.2 to address IE compatibility issues. After updating, click events are throwing an error that blocks future events. Dragging and dropping works, all events fired by table-dragger work as well.
Setup
component template
<table
id="report-table"
class="table report-table"
ng-class="{ loading: $ctrl.isFetchingRows }"
>
<thead>
<tr id="report-columns">
<th
ng-repeat="header in $ctrl.headers.displayed track by $index"
class="report-table-header"
>
<span ng-bind="header.viewFieldName"></span>
<i class="fa fa-bars report-table-drag"></i>
</th>
</tr>
</thead>
<tbody>
<tr
ng-repeat="row in $ctrl.rows.displayed track by $index"
id="report-table-row{{ $index }}"
>
<td
ng-repeat="cell in row track by $index"
class="report-table-cell"
ng-class="$ctrl.headers.displayed[$index].modelFieldName"
ng-attr-data-value="{{ cell.toLowerCase() }}"
>
<span ng-bind-html="cell"></span>
</td>
</tbody>
</table>
component controller
registerTableDragger = () => {
const element = document.getElementById('report-table');
this.dragger = tableDragger(element, {
mode: 'column'
});
this.dragger.on('drop', (origin: number, dest: number) => {
if (origin !== dest) {
const newHeaders = [...this.headers.displayed];
const [colToMove] = newHeaders.splice(origin, 1);
newHeaders.splice(dest, 0, colToMove);
this.headers.displayed = newHeaders;
this.onColReorder({ headers: newHeaders });
}
});
}
Clicking (but not dragging) one of the column headers produces this console error:
Uncaught rn {message: 'no elements in sequence', name: 'EmptyError'}
eval @ table-dragger.js:1
setTimeout (async)
a @ table-dragger.js:1
n.error @ table-dragger.js:1
n._error @ table-dragger.js:1
n.error @ table-dragger.js:1
n.notifyError @ table-dragger.js:1
n._error @ table-dragger.js:1
n.error @ table-dragger.js:1
n._error @ table-dragger.js:1
n.error @ table-dragger.js:1
n._complete @ table-dragger.js:1
n.complete @ table-dragger.js:1
n._complete @ table-dragger.js:1
n.complete @ table-dragger.js:1
n._complete @ table-dragger.js:1
n.complete @ table-dragger.js:1
n._complete @ table-dragger.js:1
n.complete @ table-dragger.js:1
n._complete @ table-dragger.js:1
n.complete @ table-dragger.js:1
n.notifyNext @ table-dragger.js:1
n._next @ table-dragger.js:1
n.next @ table-dragger.js:1
eval @ table-dragger.js:1
As far as I can ascertain this error is being thrown by the firstDrag$
rxjs Observable
This code doesn't work for me
tbody
tr ng-repeat="item in elements"
td{{item.name}}/td
td{{item.date}}/td
/tr
/tbody
wanted to remove the webpack css loader
dependency from your dist/
script (dist/
is for scripts that do not have dependencies on the underlying system, that are ready for CDN.)
couldn't. after npm install
i am still unable to npm build
.
John-Haugeland:table-dragger johnhaugeland$ npm install
npm WARN deprecated [email protected]: Package is deprecated, use https://github.com/deepsweet/istanbul-instrumenter-loader
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated [email protected]: Use uuid module instead
> [email protected] install /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/fsevents
> node install
[fsevents] Success: "/Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> [email protected] install /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-macosx.zip
Saving to /var/folders/g0/mp5zs14x5gjclfpxx8bqrhsc0000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip
Receiving...
[=======================================-] 99%
Received 16746K total.
Extracting zip contents
Removing /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /var/folders/g0/mp5zs14x5gjclfpxx8bqrhsc0000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip-extract-1504663910464/phantomjs-2.1.1-macosx -> /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
> [email protected] install /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/chromedriver
> node install.js
Downloading https://chromedriver.storage.googleapis.com/2.32/chromedriver_mac64.zip
Saving to /var/folders/g0/mp5zs14x5gjclfpxx8bqrhsc0000gn/T/chromedriver/chromedriver_mac64.zip
Received 781K...
Received 1568K...
Received 2352K...
Received 3136K...
Received 3920K...
Received 4704K...
Received 5084K total.
Extracting zip contents
Copying to target path /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/chromedriver/lib/chromedriver
Fixing file permissions
Done. ChromeDriver binary available at /Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/chromedriver/lib/chromedriver/chromedriver
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] requires a peer of sinon@^2.1.0 but none was installed.
added 1120 packages in 37.159s
John-Haugeland:table-dragger johnhaugeland$ npm run build
> [email protected] build /Users/johnhaugeland/projects/crop6/node_modules/table-dragger
> webpack --progress --hide-modules --config webpack.build.min.js && webpack --progress --hide-modules --config webpack.build.js
module.js:491
throw err;
^
Error: Cannot find module '/Users/johnhaugeland/projects/crop6/node_modules/table-dragger/webpack.build.min.js'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at module.exports (/Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/webpack/bin/convert-argv.js:80:13)
at Object.<anonymous> (/Users/johnhaugeland/projects/crop6/node_modules/table-dragger/node_modules/webpack/bin/webpack.js:39:40)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `webpack --progress --hide-modules --config webpack.build.min.js && webpack --progress --hide-modules --config webpack.build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/johnhaugeland/.npm/_logs/2017-09-06T02_12_01_411Z-debug.log
John-Haugeland:table-dragger johnhaugeland$ cat package.json
table crash if in td or th exists attr colspan or rowspan
I get exceptions running the demo and attempting to drag columns.
Add unit test
Hi,
Is possible to set an initial order?
What I want to do, is save a json/string with the order and next time restore the previous order.
on trying to bundle with browserify:
> browserify -r ./build/crop6.es5.js:crop6 -o build/crop6.es5.cjs.js
Error: Cannot find module '!!./../node_modules/.npminstall/css-loader/0.26.1/css-loader/index.js!./main.css' from '/Users/johnhaugeland/projects/crop6/node_modules/table-dragger/dist'
at /Users/johnhaugeland/projects/crop6/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
at process (/Users/johnhaugeland/projects/crop6/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
at ondir (/Users/johnhaugeland/projects/crop6/node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
at load (/Users/johnhaugeland/projects/crop6/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
at onex (/Users/johnhaugeland/projects/crop6/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
at /Users/johnhaugeland/projects/crop6/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:152:21)
npm ERR! code ELIFECYCLE
is there a way to use this library where i can just handle the css myself?
I have added table-dragger version 1.0.2 into my react project. It is working perfect with chrome but not with IE11. This is really nice library, so i want to resolve this issue ASAP. Please help, its urgent.
I really like your demo especially the motion when dragging the columns.
But is there a way to use the script without having to do import tableDragger from 'table-dragger
The doc say "easily add drag-and-drop sorting to your table without jQuery", but if you need a build tool to make the script work, I think you must remove "easily" from the title ;-)
Hi there,
I've been having some trouble regarding table CSS styles.
The probem is actually solved on my end, I just wanted to throw out that the documentation should specify somewhere how CSS should be written.
For instance, table styles should target table by class, not id or some inheritance, otherwise styles will not be added the dragging rows.
Other example: some bootstrap classes may conflict with drag and drop features (mt-5 for example that gives a certain amount of margin on the table actually adds margins to the dragging row).
First of all, I love this plugin!
In our current project, I'm required to provide table row resequencing feature. With this plugin I was able to do that with one hand tied behind my back :D. I'm also required to provide drag and drop of items in lists, all the while keeping download size to a minimum.
I saw table dragger
requires dragula-with-animation
to work, but packs it internally. So it's there but not there, if you catch my meaning.
Is it possible to make table dragger require dragula-with-animation
as an external dependency?
Otherwise I'll end up having a duplicate dragula-with-animation
plugin added to my solution.
Thanks in advance.
This is great plugin! But, When I generate the row dynamically, I found that some table rows were invalid
Thanks for a very good plugin it works very nicely there is just on exception where I got stuck
Add multiple columns so that you have horizontal scroll (overflow-x:true) .
When you start to drag the column beyond the visible scroll view the fakeColumn does below the table and it does not work.
Do you know why that happens.
@sindu12jun
While dragging another td in a table which was configured as table-draggable, specific td should not be draggable and droppable. I need that to be fixed.
Please refer this link, https://output.jsbin.com/papohan/1
Please fix any one column (first or last) to be pinned. not to be moved while swapping other td's in table.
In the event trigger, when I move one row, I am able to get the new index of the same, but due to that, the other row positions also change.
How do I fetch the new indexes of all the rows?
Dear,
Could you please remove the line: ' console.log' calls ?
That makes appear text in the console to each drag (I have actually the npm version).
Thank you.
Excellent piece of code but there is a Problem. Dynamically Injected a table Column, is not draggable. I insert table Column with Class name "handle sindu_handle" but it didn't work, Anyone Have any Suggestion or fix for this.
regards.
The class sindu_handle
is added to the first column even when onlyBody
is set to true
.
I am getting an error below in my angular 8 application
Uncaught TypeError: Cannot read property 'CustomEvent' of undefined
at Object. (table-dragger.js:4098)
I am using Typescript : 3.5.3
It works okay with Angular 6 (typescript: 2.5)
just wondering if you have any idea what can cause this error
thanks
Awesome piece of code, I could not even begin to understand it.
However, I find I cannot get it to work properly if tableDragger() is passed a table that is embedded inside another table. The rows jump to the top of the whole window while they are being dragged, and cannot be moved to a new position.
I'm after creating a large table with draggable rows at different levels.
Any reason that would not work?
Greetings.
When setting table to onlyBody:true unable to drag row to top row when using chrome on android tablet.
Works fine in desktop browser.
Thank you in advance for your consideration
dragger.on('drop', (from, to, el, mode) => {
console.log(drop ${el.nodeName} from ${from} ${mode} to ${to} ${mode}
);
this.form = from; // unable to set global varibale.
this.to = to; // unable to set global varibale.
this.tableSort(from, to); // unable to call other methods
})
您好!这个库对我来说非常有帮助,感谢分享!但是在使用的时候发现一些问题:
.sindu_dragger
这个元素只做了位置的处理而没有做宽高的处理,无法使它的大小和原表格保持一致。我在源码的2522行后增加了两行代码,情况会好一些,但仍期望官网能改善一下 // 原代码块
(0, _util.css)(el, {
position: 'absolute',
top: originEl.offsetTop + 'px',
left: originEl.offsetLeft + 'px',
});
// 我修改后
(0, _util.css)(el, {
position: 'absolute',
top: originEl.offsetTop + 'px',
left: originEl.offsetLeft + 'px',
width: originEl.parentNode.offsetWidth + 'px',
height: originEl.parentNode.offsetHeight + 'px'
});
red
改为rgba(255,255,255,0.2)
会好一点._mirror
元素的overflow设置为hidden(3169行),如下 _mirror.style.overflow = 'hidden';
_mirror.style.width = _item.parentNode.offsetWidth + 'px';
_mirror.style.height = _item.parentNode.offsetHeight + 'px' ;
using class component.
It works on PC, but not on mobile.
No dragging.
Is there a workaround?
Currently, I find the library was not support for dragging a rowspan or colspan td, and I want to know whether this feature is in plan.
Ive noticed the ui becomes ultra slow with 80+ rows (in my case) and becomes almost unusable with bigger numbers, is there some sort of optimization or change we can make to make it smoother?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.