Column Filtering with Reordering - searches wrong column after reorder?

Column Filtering with Reordering - searches wrong column after reorder?

tomnftomnf Posts: 1Questions: 0Answers: 0
edited August 2011 in Bug reports
Hi,

I'm new to DataTables so forgive me if I'm missing something!

I am using Individual Column Filtering as well as Column Reordering. Both work great by themselves, but if I move a column to a later position and attempt to use it's filter, it filters data from the column that's now at it's original index instead of the column I am trying to filter on.

I did some debugging and can see it's passing the column's "new" index to the oTable.fnFilter function, which seems correct, so I can't understand why/how it would be filtering a different column.

I couldn't find any examples of the two being used together with filtering turned on - does anyone know if this should work or how to resolve?

Thanks,
Tom

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    there's a separation of DOM elements (table, row, cell) and their indexes vs. the internal data held in DataTables (aoData, aoColumns, etc.). When you re-order columns in the DOM, the internal column indexes remain the same.

    you can scan through oTable.fnSettings().aoColumns[] to match column names to column numbers rather than hard-coding an index number, if this makes your code more readable and manageable.
  • Ironwil616Ironwil616 Posts: 50Questions: 0Answers: 0
    edited October 2011
    I'm having the same problem, but I don't really understand your answer. In my case I only have some columns being filtered, and I applied this to avoid incorrect index assignment:

    [code]
    var index = $(this).parent("tr").children().index($(this));

    if (index)
    {
    this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(index));
    $('select', this).change(function()
    {
    oTable.fnFilter($(this).val(), index);
    });
    }
    [/code]

    This works great, but the trick is to get it to run when a column is dragged and dropped. I'm not sure what callback I can tap for this. The draw callback didn't fire after dropping a column into a new place. If I was able to tap into a callback, I could use the above code without the line that assigns the innerHTML to reset the indexes, I believe.
This discussion has been closed.