Giter VIP home page Giter VIP logo

rowreorder's Introduction

RowReorder

RowReorder adds the ability for rows in a DataTable to be reordered through user interaction with the table (click and drag / touch and drag). Integration with Editor's multi-row editing feature is also available to update rows immediately.

Installation

To use RowReorder the primary way to obtain the software is to use the DataTables downloader. You can also include the individual files from the DataTables CDN. See the documentation for full details.

NPM and Bower

If you prefer to use a package manager such as NPM or Bower, distribution repositories are available with software built from this repository under the name datatables.net-rowreorder. Styling packages for Bootstrap, Foundation and other styling libraries are also available by adding a suffix to the package name.

Please see the DataTables NPM and Bower installation pages for further information. The DataTables installation manual also has details on how to use package managers with DataTables.

Basic usage

RowReorder is initialised using the rowReorder option in the DataTables constructor - a simple boolean true will enable the feature. Further options can be specified using this option as an object - see the documentation for details.

Example:

$(document).ready( function () {
    $('#myTable').DataTable( {
    	rowReorder: true
    } );
} );

Documentation / support

GitHub

If you fancy getting involved with the development of RowReorder and help make it better, please refer to its GitHub repo.

rowreorder's People

Contributors

allanjard avatar colin0117 avatar gwrey avatar jazo avatar kissgab avatar muellermatthew avatar paddyhamburg avatar ryantse avatar sandydatatables avatar themming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rowreorder's Issues

Keyboard-driven method for reordering rows

This idea was brought up before:

          It would also be massively useful when trying to provide a keyboard-driven alternative method for reordering rows, for use by the vision-impaired or others with special needs.

Originally posted by @QuixoteOne in #10 (comment)

We want to provide row reordering functionality for our users, but if it doesn't work via the keyboard, we wouldn't be able to provide an equitable experience for our users. It would also open us up to legal concerns.

As far as implementation:

  • The draggable selector needs to be focusable
  • A keyboard shortcut that is already popular for manual sorting (for example, Google Tasks seems to use Ctrl-UpArrow and Ctrl-DownArrow)
  • Optional: For the keyboard, the position calculations shouldn't need to use X/Y coordinates. Thus, it may be good to segment the existing code such that the "where did the mouse/drag start/end" code that calculates the old and new positions is separate from the "change row position" code.

Thank you for considering this request! ❤️

Selector-Modifier to support RowReorder

Like table.rows({order: 'applied'}).data() ,
there should be table.rows({rowReorder: 'applied'}).data() ,
so that I can get all data() in table based on current reorder state

Reorder on Sort enhancement

In the following example:
http://www.datatables.net/extensions/rowreorder/examples/initialisation/simple.html
when a user sorts data on the table it does not alter the sequence numbers, so a user cannot use the sorts to reset the sequence numbers before customizing the sequence orders, so if a users has a particular sequence order right now they have to manually drag each item on the list into the right sequence.

Instead I think that when a user sorts the data by any of the columns other than the first column, there should be a setting to update the Seq. numbers with the newly sorted order. 'reorderOnSort: true or false' so that if i sort by names, then the first number in the sequence would be 'Airi Satou', and the sort numbers would proceed in alphabetical order.
If the new option is 'true', the table will create a event listener on sorting, or perhaps the fnDrawCallback, and then after a table has changed, it updates the sequence numbers to whatever new position they are in the table.

Secondly, when a row is manually reordered by a users, the sort should automatically be removed from whichever column has it, and if the Seq. column is visible, it will indicate that the rows are now sorted by the Seq. column. Thus if the table is sorted by names, and then I drag a name to a different spot on the list, with the 'reorderOnSort' as true, the sort indicator would switch to the seq. list when it updates the positions since the list is no longer sorted by names.

Speed up reorder when a lot of rows shown

Hi

Ran into a performance problem when reordering a table with more than 300 rows. It actually gets slowly worse the more rows added.
After a bit of digging we found what was causing it to be slow:
image

The inserting causes the drag to not be as smooth as you would hope. If you are dragging a item up past 100+ items it can get very annoying.

The solution we came up with was to move that logic into a debounced method, meaning if the user stops dragging for x milliseconds it then calls the function. This has greatly improved the performance for dragging rows and is a lot more scalable.

However, I thought I would post on here to see if we were missing something?

Support Programmatic Reordering

It would be useful if the extension supported programmatic reordering through an API call like table.rows().reorder(fromIndex, toIndex). Effectively performing the same operation as the drag and drop via an API call.

My use case is that I allow the user to select a number of rows then move them to the top of the table when they click a button. A programmatic API for reordering would simplify this greatly.

Bug when using rowreorder extension together with the scroller extension

Hello,

there is a bug when using rowreorder extension together with the scroller extension.
Example to reproduce bug:
https://jsfiddle.net/99358x8p/10/

To reproduce the bug use the following steps:

  1. Drag first row to a position greater than row 30.
  2. Scroll up to the top row.
  3. You can see identical and wrong sequence numbers everywhere. The ordering/data is broken.

It works if you only reorder the row to a near position. At what distance the bug occurs depends on the scrollY value of the datatable. With smaller scrollY value the bug occurs sooner.

Is there any workaround?

Many thanks for any answer. Best regards.

Add Ajax Initialisation Example

I think it would be useful if there was an example of using RowReorder with Ajax. It took a good bit of searching today for me to discover that I need to use dataSrc to reference the data to be used for ordering.

I also came a across a few instances on the forum where this example could have helped.

Preserving row attributes / proper row reordering

To start, RowReorder extension has an issue in the process of reorder. Actually I have 2 issues, 1 is connected to row reorder the other one is with keeping attributes on row. I'll explain.

When you reorder, it does move rows around and change the number of row, but the actual index is not changed.

I have a function that when I click on a button in row, the row between gets added, I use a for loop that gets the index of element where I clicked, adds a row to the datatable and starts moving it around to desired position:

[0][1][2][3][4->][<-newRow]
[0][1][2][3->][<-newRow][4]
[0][1][2->][<-newRow][3][4]
 insertedRow = table.row(rowCount).node(),
                insertedRowData = table.row(insertedRow).data(),
                tempRow,
                rowCount = table.data().length-1
                tempRowData;

            //move added row to desired index
            for (var i=rowCount;i>index+1;i--) {
                tempRow = table.row(i-1).node();
                tempRowData = table.row(tempRow).data();
                table.row(i).data(tempRowData);
                table.cell(i,0).data(i+1);
                table.row(i-1).data(insertedRowData);
            }

To add a row between I need to get the index of a row on which I clicked, I get it by using:

index = table.row(el).index();

So let's say I have 4 rows, I drag the last one to second position and when I click on it, to add a row between it will actually add a row to the 5th position, because when row reorder is over the index is still 4 even tho in html it will say 2.

To fix that I turned off the update in rowReorder

rowReorder: {
                    snapX: 7,
                    update: false
                },

And on row-reorder event I added

for (var i=diff.length - 1; i>=0; i--) {
                    diff[i].nodeData = table.row(diff[i].node).data();
                }

                for (var i = table.data().length-1; i >= 0; i--) {
                    for (var j = diff.length - 1; j >= 0; j--) {
                        if(i === diff[j].newPosition) {
                            table.row(i).data(diff[j].nodeData);
                            table.cell(i,0).data(diff[j].newData);
                            i--;
                        }
                    }
                }

Which is pretty similar to my row between loop. It works nicely, but the thing is, that I have different html attributes on row and I need to move them along, but since all those functions affect only the inner data, I can't achieve this.

I wrote a copyAttribute function for my rowReorder and rowBetween:

$.fn.copyAllAttributes = function (sourceElement, erase, copyClass, ignoreAttr) {
        erase = erase || false;
        copyClass = copyClass || false;
        ignoreAttr = ignoreAttr || '';

        // 'that' contains a pointer to the destination element
        var that = this;

        // Place holder for all attributes
        var allAttributes = $(sourceElement).prop("attributes"),
            attrString = '';

        if (allAttributes && that.length == 1) {
            $.each(allAttributes, function () {
                // Ensure that class names are not copied but rather added
                if(this.name == "class"){
                    copyClass ? that.addClass(this.value) : 0;
                } else if (ignoreAttr.indexOf(this.name) == -1){
                    that.attr(this.name, this.value);
                    attrString += ' ';
                    attrString += this.name;
                }
            });

            erase ? $(sourceElement).removeAttr(attrString) :0; // bug
        }
        return that;
    };

But they are preserved only until datatable has to manipulate the html again, as soon as it happens everything is like cache reverted or changed...

Any advice how can I keep my attributes and move them along? This is what I'm interested in the most, rowReorder itself can be left the way it is.

Row sequence corrupted when reordering a row on a filtered table and pressing Ctrl-z

We've noticed that if you filter a table and drag a row, but press Ctrl-z whilst doing so, it corrupts the row sequence or at least the rendering of it.

Pressing Ctrl-z whilst dragging a row changes the search input (basically calling undo on the input). When dropping a row into a new position the table ends up with duplicate values in the sequence column.

Test case

Expected: The row should be in the new position.
Actual: The row has not moved and the sequence column contains a duplicate value of 20.

AMD dependency is wrong

I submitted a pull request for this.

The AMD dependency is on datatables.net when it should be just "datatables"

Event on row reorder initialisation

Would you be open to the idea of adding a new configuration option for RowReorder that allows a callback to be specified that is called before reorder interaction is initialised?

We are using a patched version of the extension internally that does this but we would prefer this to be merged upstream if acceptable.

New option:

rowReorder: {
    preReorder: function preReorderCallback() {
        // Code to run before reorder is initialised
    }
}

This is called in the mousedown handler within the extension, if the option is defined in the configuration.

with rowreoder while dragging a row , rows are not completely scrolling upto last row

Dear Team,
I am using row reorder with draging . while dragging the rows unable to scoll completely down up to last row in the page. i tried this roworder with scroller plugin also its not working please find my configuration. please provide solution with rowreoder only.

"bDestroy": true,
"bDestroy": true,
"bPaginate": true,
"bInfo": true,
'iDisplayLength': 10,
'scrollCollapse': true,
'scroller': true,
rowReorder: {
'selector': '.dragable',
'update': false
},

Drag drop animation improvement

When dragging a row up or down and hovering over a row, it would look nicer if the destination row being hovered over was blank to clearly show that it's the destination row - this is how Trello does it and I find it much more intuitive.

Handling Child Rows

I have been playing around using child rows in datatables along with the row reorder, but currently the child rows are not fully supported when reordering rows, so I have begun to work on a fix.
In order to better support the reordering of rows with attached children the following needs to happen:

  1. When creating the floating 'clone' row we should check for children, and if there are children rows we should include them inside the 'clone'.
  2. The border which is drawn around both the clone, and the original row when it is changing rows in the table needs to be extended to include any and all child rows.
  3. When the original row is moved upward in the table the child row needs to move with it(currently the child row only moves downward in the table with its parent.
  4. After the user moves a row the table is redrawn which automatically closes all of the child rows. If a table has a child row there needs to be an event listener for the 'redraw' event which will reopen any child row which was automatically closed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.