ocin35
ocin35

Reputation: 1

datatable different filter according to column?

I would like to filter on 1 column the values ​​lower than the entered value and not different as this code allows is it possible to apply this rule only on a single column? (the other columns remain different from) thank you

table.columns().every( function () {
    var that = this;
    $( 'input', this.header() ).on( 'keyup change clear', function () {
        if (that.search() !== this.value) {
            that
                .search(this.value).draw();
        }
    } );
} );

Upvotes: 0

Views: 46

Answers (1)

mark_b
mark_b

Reputation: 1471

Each column has an index, which starts at 0 counting from the left. You can pass this index into your function and then for each column if the index is one value do one thing, otherwise do another. Let's say you want to apply this to the second column, which has a column index of 1. Then your code above would look something like this:

table.columns().every( function (columnIndex) {
    var that = this;
    if(columnIndex === 1) {
        $( 'input', this.header() ).on( 'keyup change clear', function () {
            if (that.search() > this.value) {
                that
                    .search(this.value).draw();
            }
        } );
    } else {
        $( 'input', this.header() ).on( 'keyup change clear', function () {
            if (that.search() !== this.value) {
                that
                    .search(this.value).draw();
            }
        } );
    }
} );

Upvotes: 1

Related Questions