G-Srikanth / dragtable

Automatically exported from code.google.com/p/dragtable
0 stars 0 forks source link

Feature Request: Exclude columns from dragging #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Desired: A method for preventing certain columns from being dragged -
perhaps through the use a class name.

Original issue reported on code.google.com by xorandno...@gmail.com on 21 Jul 2008 at 7:39

GoogleCodeExporter commented 9 years ago
default:  
var headers = table.tHead.rows[0].cells;
    for (var i = 0; i < headers.length; i++) {
      headers[i].onmousedown = dragtable.dragStart;
    }
I want to freeze the first column
 so, I set:
var headers = table.tHead.rows[0].cells;
    for (var i = 1; i < headers.length; i++) {
      headers[i].onmousedown = dragtable.dragStart;
    }

Original comment by minglian...@gmail.com on 17 Dec 2008 at 2:27

GoogleCodeExporter commented 9 years ago
it would be more helpful to be able to freeze more than just the first column, 
not so 
statically

Original comment by maxstrue...@gmail.com on 30 Jun 2009 at 8:18

GoogleCodeExporter commented 9 years ago
I'm not sure I entirely understand this request. Say you want to freeze the 
leftmost
column. Does this mean that:

1. the leftmost column cannot be dragged?
2. it will always be the leftmost column?

If a column itself can't be dragged, you can always just drag the other columns
around it. Implementing #1 is easy (I'd add a "frozen" class and not set 
onmousedown
for that column). Implementing #2 is harder.

Original comment by danvdk on 30 Jun 2009 at 8:57

GoogleCodeExporter commented 9 years ago

Original comment by danvdk on 30 Jun 2009 at 8:58

GoogleCodeExporter commented 9 years ago
I have a revision on this portion. What I did was I added a dragindic attribute 
to my
headers, then in the makeDraggable I checked if the dragindic attribute is 
equals to
"1", if it is then it will enable the dragStart else then no dragging of 
columns allowed.

makeDraggable: function(table) {
    if (table.getElementsByTagName('thead').length == 0) {
      the = document.createElement('thead');
      the.appendChild(table.rows[0]);
      table.insertBefore(the,table.firstChild);
    }

    // Safari doesn't support table.tHead, sigh
    if (table.tHead == null) {
      table.tHead = table.getElementsByTagName('thead')[0];
    }

    // to check if the corresponding column is draggable
    var headers = table.tHead.rows[0].cells;
    for (var i = 0; i < headers.length; i++) {
        if(headers[i].getAttribute('dragindic') == "1"){
            headers[i].onmousedown = dragtable.dragStart;
        }
    }
  },

And in the dragEnd, I also check if dragindic equals to 1 so that it won't be
replaced by the dragged column.

dragEnd: function(event) {
    if (dragtable.browser.isIE) {
      document.detachEvent("onmousemove", dragtable.dragMove);
      document.detachEvent("onmouseup", dragtable.dragEnd);
    } else {
      document.removeEventListener("mousemove", dragtable.dragMove, true);
      document.removeEventListener("mouseup", dragtable.dragEnd, true);
    }

    // If the floating header wasn't added, the mouse didn't move far enough.
    var dragObj = dragtable.dragObj;
    if (!dragObj.addedNode) {
      return;
    }
    dragObj.tableContainer.removeChild(dragObj.elNode);

    // Determine whether the drag ended over the table, and over which column.
    var pos = dragtable.eventPosition(event);
    var table_pos = dragtable.absolutePosition(dragObj.table);

    if (pos.y < table_pos.y ||
        pos.y > table_pos.y + dragObj.table.offsetHeight) {
      return;
    }
    var targetCol = dragtable.findColumn(dragObj.table, pos.x);

if(dragObj.table.tHead.rows[0].cells[targetCol].getAttribute('dragindic') != 
"1"){ 
        return;
    }

    if (targetCol != -1 && targetCol != dragObj.startCol) {
        dragtable.moveColumn(dragObj.table, dragObj.startCol, targetCol);
    }
  },

Original comment by sera...@gmail.com on 26 Oct 2009 at 11:27

GoogleCodeExporter commented 9 years ago
I made a quick amendment to the script to prevent certain columns from being
draggable by class name. Add the class "nodrag" to the table head and add this 
code
to line 107:

if( headers[i].className != 'nodrag' )

Original comment by symbiant...@gmail.com on 15 Jan 2010 at 8:43

GoogleCodeExporter commented 9 years ago
Beauty!  Thanks.

Original comment by xorandno...@gmail.com on 15 Jan 2010 at 8:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I had a need to keep some left-most and right-most columns from being dragged or
being a drag target (in certain circumstances) - here's the amendments I made:

line 197:
    if (dragObj.origNode.className.indexOf("not-draggable") > -1) {
        return;
    }

line 337:
    header = dragObj.table.tHead.rows[0].cells
    if (header[targetCol].className.indexOf("not-draggable") > -1) {
        return;
    }

Original comment by dalebreidy@gmail.com on 18 Mar 2010 at 10:36