title: Adding sortBy attribute programatically to primefaces DataTable Column
body: <p>I'm trying to put the <code>sortBy</code> attribute into the primefaces datatable <code>Column</code> programatically. I have inherited from DataTable, and creating my own Columns using a custom <code>getColumns()</code> call.</p>
  
  <p>Unfortunately there seems to be no clean way to insert the sortBy attribute to the column, since the method yet doesn't know the context it is in.</p>
  
  <pre><code>public List&lt;Column&gt; getColumns() {
      if (columns == null) {
          columns = new ArrayList&lt;Column&gt;();
          String[] columnStrings = getShowColumns().split(",");
          for (String columnString : columnStrings) {
              Column column = getColumnByType(columnString.trim());
              if (column != null) {
                  //here I have to add the sortBy Expression somehow,
                  //but there is no context to construct it from
                  //column.setSortBy(ValueExpression)
                  columns.add(column);
              }
          }
      }
      return columns;
  }
  </code></pre>
  
  <p>It seems obvious to me, that I am missing something, but I am lost rightnow. The <code>Column</code> seems to be filled with that <code>ValueExpression</code> somewhere else, but I can't find out where...</p>
  
  <p>I tried to go through all the code using the debugger, but I can't figure out when the ValueExpression is generated in the original implementation. Any hints appreciated.</p>