Option order in column select filters

Option order in column select filters

iecwebmastiecwebmast Posts: 66Questions: 9Answers: 1
edited October 2010 in General
Is there a way to reorder select filter the options alphabetically?
I plan to use this feature in a number of pages to allow users to filter information displayed.
Datatables works great for this. I would just like to help people find things in the list easier.
The options in each column select filter are in the order they appear in the table, which is more often than not all mixed up.
Here is an example of a simple page. If you look at the "Committee" or "Country" filters you will see the dilemma.
http://beta.iec.ch/about/awards/1906/1906_recipients_2010.htm

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Probably the easiest way is to add a call to Array.sort() at the end of the fnGetColumnData function. asResultData.sort(); should probably do it.

    Allan
  • mgmg Posts: 47Questions: 0Answers: 0
    edited February 2011
    This point seems absolutely critical to making the select feature useful (if you are not generating your select elements server-side).

    Maybe the demo page should be updated to add the .sort().

    So instead of:

    [code]
    $("tfoot th").each( function ( i ) {
    this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) );
    $('select', this).change( function () {
    oTable.fnFilter( $(this).val(), i );
    } );
    } );
    [/code]
    ...change to:
    [code]
    $("tfoot th").each( function ( i ) {
    this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i).sort() );
    $('select', this).change( function () {
    oTable.fnFilter( $(this).val(), i );
    } );
    } );
    [/code]
This discussion has been closed.