Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong number of filter inputs #2

Closed
vibezzz opened this issue Sep 16, 2011 · 5 comments
Closed

wrong number of filter inputs #2

vibezzz opened this issue Sep 16, 2011 · 5 comments

Comments

@vibezzz
Copy link

vibezzz commented Sep 16, 2011

I have jquery ui tabs loaded via ajax. Each tab has tables with unique ID and tablesorter on them (with zebra and filter widgets).
When I click tabs one by one, tablesorter adds wrong number of filter inputs to tables:

(1st ut tab)
table with 2 columns

(2nd ut tab)
table with 3 columns

(3rd ut tab)
table with 2 columns - there i have 3 filter inputs


i think this bug in tablesorter becouse filter gets number of columns from it (that have not been updated from last tab)
my solution was changing line

cols = c.headerList.length,
to
cols = $("thead th", table).length,

in filter widget. It works but i dont think that good way to fix this. Check please)

@Mottie
Copy link
Owner

Mottie commented Sep 16, 2011

Hmm, the c.headerList.length should work as it is. And your fix shouldn't make a difference, but hey it works and it looks like a good way to get around the problem to me - be confident in yourself ;)

I'd still like to know why there's a difference and the question that comes to mind is about the third tab table. Could you look at it with Firebug or its equivalent and see what the headerList contains? Enter this in the console to get the information:

$('table#yourID')[0].config.headerList

It might contain a clue as to why there is an extra header listed, or not. The bug could very well be in the widget that I haven't encountered a test case for - I did put together the widget rather quickly and without extensive testing.

Thanks for the report!
I'll keep looking too

@vibezzz
Copy link
Author

vibezzz commented Sep 16, 2011

Yes, there is old header from table with bigger column number at end of list (b.t.w. when i select ui tab 1 after tab 2 there is extra filter input too).
Seems like headerList is not unique for every table and has not been cleaned before adding new headers by index.
All works fine if add table.config.headerList = []; after 402 line in tablesorter.js before "each" cycle that adds headers in list, with no need to fix widget.

...
function buildHeaders(table) {
                var meta = ($.metadata) ? true : false,
                header_index = computeTableHeaderCellIndexes(table),
                $th, lock, time, $tableHeaders;
                if (table.config.debug) {
                    time = new Date();
                }

                                table.config.headerList = []; ---- here

                $tableHeaders = $(table.config.selectorHeaders, table)
....

Don't know how it affects on other code but filter works fine for me) Is this good way?

@vibezzz vibezzz closed this as completed Sep 16, 2011
@vibezzz vibezzz reopened this Sep 16, 2011
@Mottie
Copy link
Owner

Mottie commented Sep 16, 2011

Ok, I just updated the plugin to v2.0.19 with your suggestion. Please check it and see if it fixes the problem.

Thanks again!

@vibezzz
Copy link
Author

vibezzz commented Sep 16, 2011

All works good with v2.0.19, thanks. You can delete this issue now.

I have also done some modification in filter widget for me to hide filter inputs by options like
headers: {6:{sorter: false, nofilter:true}}

so i can use this to hide input and disable sort on 6 column in table:)
$("#mytable").tablesorter({headers: {6:{sorter: false, nofilter:true}}, widgets: ['zebra','filter']});

if you interested in it, replace line 99 in widgets to:

if(!(typeof(c.headers[i])!=="undefined" && "nofilter" in c.headers[i])){
   fr += '<td><input type="text" class="filter" data-col="' + i + '"></td>';
}
else  {
   fr += '<td><input type="text" style="visibility:hidden;" class="filter" data-col="' + i + '"></td>';
}

@vibezzz vibezzz closed this as completed Sep 16, 2011
@Mottie
Copy link
Owner

Mottie commented Sep 16, 2011

Hey Jizo!

Thanks again... I've updated the plugin to 2.0.20 and included the ability to use "filter-false" class name in the header to disable the filter :)

Thanks again, you Rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants