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

Duplicate AJAX requests using the filter formatter widget with server-side options #372

Closed
sbine opened this issue Sep 4, 2013 · 8 comments
Labels

Comments

@sbine
Copy link

sbine commented Sep 4, 2013

I'm using tablesorter with server-side pagination, sorting, and filtering. It seems that setting initial filter values using the filter formatter widget causes two (sometimes three) identical AJAX requests to be fired when the table is first loaded. Subsequent filters behave as expected.

For example:

function($cell, indx) {
    return $.tablesorter.filterFormatter.html5Range( $cell, indx, {
        value: 600,
        min: 0,
        max: 800,
        delayed: true,
        valueToHeader: false,
        exactMatch: false
    });
}

sends the request twice

?page=0&size=25&filter[2]=600&sort[1]=1
?page=0&size=25&filter[2]=600&sort[1]=1

Since this only occurs when the table is first loaded I suspect it may be related to #343. Any help would be appreciated, and thank you for your work on this amazing plugin.

@Mottie
Copy link
Owner

Mottie commented Sep 30, 2013

Hi @sbine!

Just letting you know I'm back and I'll be looking into this issue. Thanks for reporting it!

@sbine
Copy link
Author

sbine commented Oct 8, 2013

Thank you @Mottie! I spent several hours today attempting to debug this issue and came up with a temporary fix.

Starting on line 279 of jquery.tablesorter.pager.js, changing:

$t.trigger('update');
c.totalPages = Math.ceil( c.totalRows / c.size );
updatePageDisplay(table, c);
fixHeight(table, c);
if (c.initialized) { $t.trigger('pagerChange', c); }

to

c.totalPages = Math.ceil( c.totalRows / c.size );
updatePageDisplay(table, c);
fixHeight(table, c);
if (c.initialized) {
    $t.trigger('pagerChange', c);
}
else {
    $t.trigger('update');
}

gets rid of one of the duplicate requests.
Due to my extremely limited knowledge of the plugin's codebase, I'm not sure if this is the correct solution, but I hope it helps you get to the root of the problem.

@Mottie
Copy link
Owner

Mottie commented Oct 8, 2013

Hmm, if you're not triggering an update, then the plugin doesn't update the cache... and umm, I guess since you're using ajax the server does all the sorting/filtering, you don't need to cache the data anyway. So, I guess just completely remove that $t.trigger('update');.... can you think of a case that would need it, within an ajax call? Hmmm.

@sbine
Copy link
Author

sbine commented Oct 8, 2013

Right, caching becomes unnecessary in my case. Perhaps caching-specific code in each widget could be skipped over when its respective server-side option is enabled?

@Mottie
Copy link
Owner

Mottie commented Oct 11, 2013

Ok, I'm hoping this bug is all squashing and isn't sticking to my shoe... I don't wanna look because it'll be icky. LOL

@sbine
Copy link
Author

sbine commented Oct 11, 2013

Hi again Mottie! As much as I hate bugs... it seems removing the update trigger does actually break table functionality. I upgraded to 2.11.0 this morning and had to make these changes to get my tables to function:

jquery.tablesorter.pager.js line 157, add back:

else {
    c.$table.trigger('update');
}

jquery.tablesorter.js line 346, add the following:

$(table).trigger("updateComplete", table);

updateComplete was not being triggered on tables without the filter formatter widget, but with all server-side options set. My tables that do use the filter formatter widget were working without this change.

Sorry for the trouble, and thank you for your help :)

@Mottie
Copy link
Owner

Mottie commented Oct 11, 2013

Hi @sbine!

Thanks for sharing how to fix it. I'll get that updated in a few minutes.

Edit: Umm, I guess the line numbers don't match the version I have... basically the same place right?

@sbine
Copy link
Author

sbine commented Oct 11, 2013

Yes, the update trigger goes where it was before. The second change was at the end of the appendToTable function, after $(table).trigger("sortEnd", table);.

Mottie added a commit that referenced this issue Oct 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants