Changeset 2488


Ignore:
Timestamp:
Aug 7, 2006, 12:13:25 PM (17 years ago)
Author:
Nicklas Nordborg
Message:

Fixed sorting problem with always visible columns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/common/columns/configure.jsp

    r2408 r2488  
    5959  <base:head>
    6060    <script language="JavaScript">
    61    
    62     // Returns indexOf first occourence of value in the options list
    63     function indexOf(options, value)
    64     {
    65       for(var index = 0; index < options.length; index++)
    66       {
    67         if(options[index].value == value)
    68         {
    69           return index;
    70         }
    71       }
    72       return -1;
    73     }
    74    
    75     function showColumns(columns)
    76     {
    77       var frm = document.forms['columns'];
    78       var visible = frm.visible;
    79       var hidden = frm.hidden;
    80 
    81       // When adding the visible columns we put them directly in the correct place by adding the current length of the visible list
    82       // which contains always visible items
    83       var l = visible.length;
    84       if(columns == 'all')
    85       {
    86         for(var i = 0;i < hidden.length; i++)
    87         {         
    88           visible[l+i] = new Option(hidden[i].innerHTML, hidden[i].value);         
    89         }
    90         hidden.length = 0;
    91       }
    92       else
    93       {
    94         var cols = columns.split(',');
    95         // We go through the hidden list backwards to be able to remove items directly
    96 
    97         for(i = 0; i < cols.length; i++)
    98         {     
    99           // Check if this column is among the visible
    100           var index = indexOf(hidden, cols[i]);
    101           if(index != -1 )
    102           {
    103             visible[visible.length] = new Option(hidden[index].innerHTML, hidden[index].value);
    104             hidden[index] = null;           
    105           }         
    106         }                 
    107       }
    108     }
    109    
    110     // Initialise the visible and hidden column lists and show the additional columns
     61
     62    // Initialise the visible and hidden column lists
    11163    function initColumns(columns)
    11264    {
     
    11769      hidden.length = 0; 
    11870
     71      // The visibled columns (comma-separated)
     72      var allVisible = columns == 'all';
     73      var visibleCols = columns.split(',');
     74
     75      // All column definitions
    11976      var columnDefs = window.opener.Table.columns;
    120       // Put all columns in the hidden list
     77
     78      // Put all column in the hidden or visible list
     79      var toList = allVisible ? visible : hidden;
    12180      for (var i = 0; i < columnDefs.length; i++)
    12281      {
    12382        var col = columnDefs[i];
    124         if (!col.alwaysHide)
     83        if (!col.alwaysHide) addCol(toList, col);
     84      }
     85     
     86      // Move visible columns to the visible list
     87      if (!allVisible)
     88      {
     89        for (var i = 0; i < visibleCols.length; i++)
    12590        {
    126           var option = new Option(col.title, col.id);
    127           if (col.alwaysShow)
    128           {
    129             option.style.fontWeight = 'bold';
    130             option.text = option.text+' ×';
    131             visible[visible.length] = option;
    132           }
    133           else
    134           {
    135             hidden[hidden.length] = option;
     91          var colId = visibleCols[i];
     92          var col = columnDefs['id'+colId];
     93          for (var j = 0; j < hidden.length; j++)
     94          {
     95            if (hidden[j].value == colId)
     96            {
     97              addCol(visible, col);
     98              hidden[j] = null;
     99              j = hidden.length;
     100            }
    136101          }
    137102        }
    138       }     
    139       showColumns(columns);
    140     }
    141    
    142 
     103       
     104        // Move columns that must be visible to the visible list
     105        for (var i = 0; i < hidden.length; i++)
     106        {
     107          var col = columnDefs['id'+hidden.options[i].value];
     108          if (col && col.alwaysShow)
     109          {
     110            addCol(visible, col);
     111            hidden[i] = null;
     112            i--;
     113          }
     114        }
     115      }
     116    }
     117   
     118    function addCol(toList, col)
     119    {
     120      var option = new Option(col.title, col.id);
     121      if (col.alwaysShow)
     122      {
     123        option.style.fontWeight = 'bold';
     124        option.text = option.text+' ×';
     125      }
     126      toList[toList.length] = option;
     127    }
    143128
    144129    // Moves all selected items in list1 to list2
Note: See TracChangeset for help on using the changeset viewer.