dynamic column toggling example conflicts with individual column filtering example

dynamic column toggling example conflicts with individual column filtering example

mleejrmleejr Posts: 7Questions: 0Answers: 0
edited July 2013 in General
I want the user to be able to dynamically show/hide columns. I have this working with this example;
http://datatables.net/beta/1.7/examples/api/show_hide.html

The user wants per-column based filtering and I have it working with this example;
http://datatables.net/examples/api/multi_filter.html

The problem is, if you combine them, when you remove a column, the filter order is still the same. For example. Let's say you have 10 columns and remove column 2. The filtering for column 10 is removed and if you type in the column filter box for column 2 (which WAS column 3), it still filters as if it's column 2. It's easy to test. Just take the per-column based filtering example and add a toggle button for any column an onclick('fnShowHide(2)'). 2 here is whatever column you want to show and hide.

ie:
Column

Just add the javascript function from the example;

function fnShowHide( iCol )
{
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#example').dataTable();

var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}

Help!

Replies

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    This plug-in should help: http://datatables.net/plug-ins/api#fnVisibleToColumnIndex . It will convert the visible column index to the column data index which is what you want for fnFilter .

    Allan
  • mleejrmleejr Posts: 7Questions: 0Answers: 0
    Thanks for your response Allan. I've read through it and added it to my web page but it's still not working. Do you know how to add it? I imported the js


    And then;

    $.fn.dataTableExt.oApi.fnVisibleToColumnIndex = function ( oSettings, iMatch )
    {
    return oSettings.oApi._fnVisibleToColumnIndex( oSettings, iMatch );
    };

    But it's still filtering on the original columns and it didn't remove the filter box for the removed column.
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Can you please link to a test page showing the problem: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
This discussion has been closed.