Undraggable column in TableHeaderComponent


#1

Hi Jules,

I’m using TableListBox and I found a problem.

A column which doesn’t have draggable flag can’t be moved when the other column was moved and inserted before/after the undraggable column, the order is changed.

I want to place some undraggable columns at the left in the table header like iTunes. In iTunes, the status column and name column are undragable and no other columns can be placed before them.

What about changing the code in the juce_TableHeaderComponent.cpp from the line 678

                for (int i = columns.size(); --i >= 0;)
                {
                    const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
                    int newIndex = currentIndex;

                    if (newIndex > 0)
                    {
                        //  check whether the previous column is draggable or not
                        const ColumnInfo* const ci = columns [newIndex - 1];
                        if (ci->propertyFlags & draggable)
                        {
                            const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
                            const int rightOfCurrent = getColumnPosition (newIndex).getRight();

                            if (abs (dragOverlayComp->getX() - leftOfPrevious)
                                < abs (dragOverlayComp->getRight() - rightOfCurrent))
                            {
                                --newIndex;
                            }
                        }
                    }

                    if (newIndex < columns.size() - 1)
                    {
                        //  check whether the next column is draggable or not
                        const ColumnInfo* const ci = columns [newIndex + 1];
                        if (ci->propertyFlags & draggable)
                        {
                            const int leftOfCurrent = getColumnPosition (newIndex).getX();
                            const int rightOfNext = getColumnPosition (newIndex + 1).getRight();

                            if (abs (dragOverlayComp->getX() - leftOfCurrent)
                                > abs (dragOverlayComp->getRight() - rightOfNext))
                            {
                                ++newIndex;
                            }
                        }
                    }

Best regards,
Masanao Hayashi


#2

That’s a very good point, I never thought of that. Thanks, I’ll add some code to enforce the order.


#3

I have checked out the latest and confirm that the issue has been fixed.
Thanks!

Masa