fnSortListener Bug?

fnSortListener Bug?

chobo2chobo2 Posts: 23Questions: 2Answers: 0
edited June 2010 in Bug reports
Hi

I am trying to use fnSortListener on one column that triggers another columns sort.

Say I have this

Column A
Column B

When column A is clicked it should use trigger Column B sort and sort. When column A again it should sort Column B again.

For me it does not. Once you clicked on column A and triggers column B that's it forever. You can click as long as you want nothing will happen.

This is what I have
[code]
oTable= $(this).dataTable
({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns":
[
null,
null
]

});

var columnA= $('#ColumnA');
oTable.fnSortListener(columnA, 1);
[/code]

Replies

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    You will need to detach the sort listeners that DataTables puts onto the the columns by default before applying your own (otherwise there will be multiple events attached) - Visual Event will be useful for this: http://www.sprymedia.co.uk/article/Visual+Event

    Also you are passing a jQuery object to the function, and it is expecting a node: http://datatables.net/api#fnSortListener . You can either use $(...)[0] or getElementById (which is the case above is faster).

    Regards,
    Allan
  • chobo2chobo2 Posts: 23Questions: 2Answers: 0
    edited June 2010
    I use jquery to get a jquery object. I was not too sure about get ElementById as I was not too sure about if it works on all browsers or if it will come with quirks in other browsers.

    I am not sure what you mean by (..)[0] I am not sure what the zero is for.

    How do you detach the sort listen?
  • chobo2chobo2 Posts: 23Questions: 2Answers: 0
    Ok I am using Visual Event and I used jquery unbind the click event. It now seems to work...expect I would like column A arrow to change as well. How would I do that?
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    1. document.getElementById - yes this will work on all browsers

    2. $(..)[0] - the jQuery object is an array of nodes returned from the selector. The 0 indicates the first node found (or indeed the only only node when using an id selector)

    3. The column sorting icons should show the column that is actively being sorted (so if you tell fnSortListener to sort on column 1, it will show column 1 as the one being sorted - even if the listener is actually on column 0). iDataSort is the way to overcome this rather than fnSortListener.

    Allan
  • chobo2chobo2 Posts: 23Questions: 2Answers: 0
    So if I want column 1 to use column 2 sort. I put under column 1 sort

    iDataSort = 1

    So jquery always gets an array back even if your selecting an id(what should only have one?)
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    [code]
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumns": [
    { "iDataSort": 1 }
    null,
    ]
    } );
    } );
    [/code]
    Now if you click on the first column, it will indicate that it is being sorted, but the data source being used is the second column (index 1). Then click on the second column - still sorting by the second column, but shown as such.

    jQuery: Yes - it's an array object with many methods and properties attached to it. Do console.dir( $('#some_id') ); in Firebug to see it.

    Allan
This discussion has been closed.