Disable all sorting after init?

Disable all sorting after init?

mmatyasmmatyas Posts: 5Questions: 0Answers: 0
edited November 2011 in General
Hi,

What is the best way to programatically disable/enable sorting of columns after init? I think the easiest would be to prevent clicking of th cells, but is there a cleaner solution? I'm open to writing a Plugin for this, but please provide any pointers.

Some background: I'm working on implementing a solution for being able to drag/drop rows by using a specific column to maintain position/order (I'm also using jQuery UI's sortable class to make rows drag-droppable). However, when this "row-drag-drop" mode is enabled, hitting any of the sort buttons totally messes everything up. So when when in this mode, which we call "ranking mode", I need to make sure the user doesn't try to sort by any columns.

Thanks,

Mark

PS. Allan, great tool by the way. Thanks for making it open source.

Replies

  • mmatyasmmatyas Posts: 5Questions: 0Answers: 0
    Ok. This was super simple given that the click handler for sorting checks if the setting for sorting is enabled/disabled. Here is a stab at an API plug-in:

    [code]
    /*
    * Turn On/Off Sorting capability
    *
    * @param {object} oSettings DataTables settings object
    * @param {array} | {string} aiColumns Array of columns or string == '_all'
    * @param {boolean} bOn True to enable, false to disable
    */
    $.fn.dataTableExt.oApi.fnSortOnOff = function ( oSettings, aiColumns, bOn )
    {
    var cols = typeof aiColumns == 'string' && aiColumns == '_all' ? oSettings.aoColumns : aiColumns;

    for ( var i = 0, len = cols.length; i < len; i++ ) {
    oSettings.aoColumns[ i ].bSortable = bOn;
    }
    }
    [/code]

    Example to disable user sorting:
    [code]
    var oTable = $('table').dataTable();

    oTable.fnSortOnOff( '_all', false );
    [/code]
This discussion has been closed.