How to exclude column in column filtering

How to exclude column in column filtering

NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I am using column filtering using this example.

The first column in my table is a "select" column, with checkoxes. I am trying to exclude it from filtering.
I can stop the input textbox from displaying by checking if column index is zero or not:
(although not sure if this is the right way of doing it or not.)

initComplete: function () {
    var api = this.api();
    var cursorPosition;
    // For each column
    api
        .columns()
        .eq(0)
        .each(function (colIdx) {
            if (colIdx != 0) {
                ...
            }
        });

However, I am not sure how to prevent the first column to be cloned in:

$('#MyTable thead tr')
    .clone(true)
    .addClass('filters')
    .appendTo('#MyTable thead');

Answers

  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961

    The columns() API as many options for selecting the columns. See the column-selector. You might be able to use :not(:first-child) to skip the first column, for example:

        api
            .columns( ":not(:first-child)" )
            .eq(0)
    

    Kevin

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

    Thank you Kevin. It is the cloning part I am struggling with.

  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961

    Ah. So you want the first column to span both header rows? After cloning you will need to remove the th in the second row and set the rowspan attribute to 2 for the first th in the first row. Like this:
    http://live.datatables.net/muqijeya/1/edit

    Kevin

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

    Thank you; that did it. I had to revert back the initial change from

    api
         .columns( ":not(:first-child)" )
         .eq(0)
    

    to

    api
        .columns( )
        .eq(0)
    
  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

    Weirdest thing happens now!
    When I type something in column X's input box, it searches column X-1.
    I think first-child of the columns has moved one to the right.

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

    Had to also change:

    api
        .column(colIdx)
        .search(....
    

    to

    api
        .column(colIdx + 1)
        .search(....
    
Sign In or Register to comment.