Drag 'n' drop columns
Drag 'n' drop columns
Hi,
I know the request for being able to drag columns to re-order has come up once or twice. I've been using a library called 'dragtable' (http://www.danvk.org/wp/dragtable/) and integrated it with DataTables, which up until today has been fine. Unfortunately, the complicated integration between DataTables, Allan's FixedHeader plugin and dragtable - not a jquery plugin - ended up with me running into an IE bug I couldn't fix.
I decided this evening to rebuild the dragtable feature as a DataTables plugin. I have the essential drag 'n' drop experience working, although a copy of the column doesn't yet float under your mouse, and there is some missing styling on the copy that is created.
(I have made an extra plugin as part of this that redraws the table using the data in oSettings.aoData/aoColumns - useful if you're interacting with that to update the information.)
I've put all the code up on pastebin and would very much appreciate any feedback: http://pastebin.com/f53745926
J.
I know the request for being able to drag columns to re-order has come up once or twice. I've been using a library called 'dragtable' (http://www.danvk.org/wp/dragtable/) and integrated it with DataTables, which up until today has been fine. Unfortunately, the complicated integration between DataTables, Allan's FixedHeader plugin and dragtable - not a jquery plugin - ended up with me running into an IE bug I couldn't fix.
I decided this evening to rebuild the dragtable feature as a DataTables plugin. I have the essential drag 'n' drop experience working, although a copy of the column doesn't yet float under your mouse, and there is some missing styling on the copy that is created.
(I have made an extra plugin as part of this that redraws the table using the data in oSettings.aoData/aoColumns - useful if you're interacting with that to update the information.)
I've put all the code up on pastebin and would very much appreciate any feedback: http://pastebin.com/f53745926
J.
This discussion has been closed.
Replies
http://pastebin.com/f4c763347
- animated dragging works
- dragging is cancelled if you move out of the table
- column copy is styled correctly
J.
http://pastebin.com/f700955e3
This is a big modification. Changes include:
- much faster creation of floating column
- works in IE!
- text-selection doesn't happen when you drag
- it's a DataTables plugin now
Known issues:
- column classes are not getting copied across
It would be great if someone would see if they can use this as a plugin for their table.
J.
Now this is awesome! :-)
I've not had a chance to actually try it out yet, but I will endeavour to do so this weekend. Nice one!
Allan
Take a look at it in action - http://tw.wiki-data.com/search?q=bank - this is the development site for the replacement to wiki-data.com.
J.
This is superb! Sorry for the delay in replying to you, things are starting to cool down a bit at this end :-)
I have two suggestions if I may:
1. Adding a visual indicator to show where the column will be inserted. With narrow columns you can easily put a dragged column into an unintended position.
2. Would it be possible to split your function which actually does the column swap into a separate plug-in, something which could be called programmatically (for example oTable.fnChangeColumns( 1, 4 ); ), and that will take care of iDataSort, filtering columns, hidden columns and all that stuff - and then your drag and drop would interface with that, allowing the developer to do something with JS if they want, or the end user to do your drag and drop.
Regards,
Allan
I am just about finished with my version of Draggable Columns, just got a few fine tweeks to do. Some of the code used is that of jnthnlstr's pastebin, however I have integrated that with JQuery UI Sortable for ease of use.
I may have to re-write it tho as a plug-in as currently for my job i have encapsulated it all directly into the dataTables stuff (Sorry :-) my boss is a real hard nutt.)
Regards,
Izzy
I have to admit I'm a little new to using plugins though.
Does anyone have an example of how to enable/install/use this plugin in javascript?
same for me, i saw it a few months ago. i took a short look into the code, generelly i's exactly what it's meant to be. If you take a look here you can see it (but not in combination with Datatables) http://www.danvk.org/wp/dragtable/
How does one actually hook it up to datatables?
http://www.wiki-data.com/search?q=bank&avid=&adv_1_field=Operational+City&adv_1_value=London&adv_2_field=Operational+Country&adv_2_value=GBR&index=0
really nice...only thing i am missing is the feature Allen already mentioned above:
1. Adding a visual indicator to show where the column will be inserted. With narrow columns you can easily put a dragged column into an unintended position.
By the way: how did he integrate that SHOW | HIDE column feature? I like it a lot. Is there a plugin available?
Greetings,
selicor
http://datatables.net/examples/api/show_hide.html
greetings,
selicor
You beat me to it. Thanks for that link. It is pretty cool. The only things that I don't like about it is the lack of a column sorting indicator and the fact that you need to double click the header to sort and the lack of multiple column sorting.
Do you know how to hook up the column dragging plugin to datatables? I'm a complete noob and don't know where to begin.
how can i intergrate (http://pastebin.com/f700955e3) that to a default DataTables Installation ?
Where do I have to include that js code ? Is there any "simple" Drag and Drop Feature / Plugin for Datatables planed ?
Thank you.
Tobi
This is really nice, is there a sample code with datatables? thanks
$('#example).html( '' );
the table can be dragged, but only for the first page, anyone knows why?
Maybe promote it to the plugin page? Or consider it as a true feature request for the future?
It looks like a feature a bunch of people would appreciate and use.
greetings
Yes, at some point column re-ordering will become a 'true' plug-in for DataTables. I think there are issues which still need to be resolved such as dealing with hidden columns, and a clearer UI - but this is quite certainly on the to-do list (there is just to much to do!).
Regards,
Allan
If we have a column reordering plug-in for Datatables now. Could you please point me to it.
Thanks a lot.
Allan