0

I have written built-in column filtering plugin for datatables and I have small trouble,

I have created text inputs in each column footer and now - on keyup I want to catch them indexes and then use it when filtering.

I'm getting parent column index by following line in my code:

var visIdx = $(this).parent().index();

It's returning properly index only when ALL columns are visible, but when one of them is hidden, then following columns returning bad indexes.

It causes that when some of columns are hidden filtering is applying to bad columns

There is my full code on fiddle: http://live.datatables.net/pulewemu/3/edit?js,console,output

1 Answer 1

1

The thing is that DataTable is creating new elements on each draw(). What you see isn't your "original" table with some hidden columns, but a totally new set of elements including only the "visible" columns.

So there is no way to get an "absolute" index from there.

What I suggest is to add that index in a data attribute in the .each() loop that defines the search inputs:

$('#example tfoot th').each(function(i) {
    var title = $(this).text();
    var hate = '<input size="4" class="fder" type="text" id="gte" placeholder="min" data-index="'+i+'" />'
    hate += '<br><input size="4" class="fder" type="text" id="lov" placeholder="max" data-index="'+i+'" />'
    $(this).html(hate);
});

And then, on keyup, retreive the index like this:

var visIdx = $(this).data("index");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.