My favorites | Sign in
Project Logo
                
New issue | Search
for
| Advanced search | Search tips
Issue 9: Feature Request: Exclude columns from dragging
1 person starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----
Type-Enhancement
Priority-Medium


Sign in to add a comment
 
Reported by xorandnotor, Jul 21, 2008
Desired: A method for preventing certain columns from being dragged -
perhaps through the use a class name.
Comment 1 by mingliangli.smth, Dec 16, 2008
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;
    }

Comment 2 by maxstruever, Jun 30, 2009
it would be more helpful to be able to freeze more than just the first column, not so 
statically

Comment 3 by danvdk, Jun 30, 2009
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.
Comment 4 by danvdk, Jun 30, 2009
(No comment was entered for this change.)
Labels: -Type-Defect Type-Enhancement
Comment 5 by seravan, Oct 26, 2009
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);
    }
  },
Sign in to add a comment

Hosted by Google Code