-
Notifications
You must be signed in to change notification settings - Fork 754
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
Remembering Filtered data #146
Comments
Hi webmatrix! You can use the filter events ( $('table')
.bind('filterInit', function() {
// check that storage ulility is loaded
if ($.tablesorter.storage) {
// get saved filters
var f = $.tablesorter.storage(this, 'tablesorter-filters') || [];
$(this).trigger('search', [f]);
}
})
.bind('filterEnd', function(){
if ($.tablesorter.storage) {
// save current filters
var f = $(this).find('.tablesorter-filter').map(function(){
return $(this).val() || '';
}).get();
$.tablesorter.storage(this, 'tablesorter-filters', f);
}
}); If you also need to save the sort, then include the |
Hi Mottie, Worked like charm. Yes. I have already included saveSort widget. Thanks for wonderful plugin and widgets.Helped a lot in our Project. Some suggestions for Version 3. Somebody has already suggested it for Calculating Footer totals. Just I want suggest " Footer Totals working with Filters" Regards, |
Hi Mottie, Firstly, a big thumbs up for your work on tablesorter ! I'm having some problems with saving filter text and was wondering if you had any suggestions. Prior to the changes you made on 17th Feb, the code you posted above worked a charm. I've got an aspx page which does auto-updates, and with the two binds you listed above, the filters would re-apply themselves to the updated table. After the changes made on the 17th though, it doesnt seem to work at all. From what I can work out, something's changed in the order of filterinit and filterend triggers. I'm not that great with javascript though, so that's kind of where my workaround attempts end. Any ideas ? Thanks, |
Hi @drlovegrove! Sorry I've been extremely busy, I'll look into this soon. |
Hi @drlovegrove! It appears that all the filter events are working as they should. And just to make sure we are on the same page, the events occur as follows:
I didn't test these events while using a |
Hi Mottie, Thanks for the replies.. Sadly, I'm not using Ok, I've added some logging to my JS, as follows: console.log("PanelLoad");
// Restore the filter state - only works with old filter widget
$(".Grid").bind('filterInit', function() {
console.log("filterInit: triggered");
// check that storage utility is loaded
if ($.tablesorter.storage) {
// get saved filters
console.log("filterInit: applying old filter");
var f = $.tablesorter.storage(this, 'tablesorter-filters') || [];
$(this).trigger('search', [f]);
console.log("filterInit: applied old filter");
}
});
// Save the filter state - only works with old filter widget
$(".Grid").bind('filterEnd', function () {
console.log("filterEnd: triggered");
if ($.tablesorter.storage) {
// save current filters
console.log("filterEnd: saving current filter");
var f = $(this).find('.tablesorter-filter').map(function () {
return $(this).val() || '';
}).get();
$.tablesorter.storage(this, 'tablesorter-filters', f);
console.log("filterEnd: saved current filter");
}
});
$(".Grid").tablesorter(
{
widgets: ["filter"],
// no fancy stuff
widgetOptions: {
// no fancy stuff
}
} When running the page, both the working and latest filter widget produce this on a refresh with nothing in the filters: PanelLoad
filterInit: triggered
filterInit: applying old filter
filterInit: applied old filter Also, typing with both gives this: filterEnd: triggered
filterEnd: saving current filter
filterEnd: saved current filter But a refresh after the filters contain text differs, and this is the problem. In the new filter, the end result is all cleared filters: PanelLoad
filterInit: triggered
filterInit: applying old filter
filterEnd: triggered
filterEnd: saving current filter
filterEnd: saved current filter
filterInit: applied old filter
filterEnd: triggered
filterEnd: saving current filter
filterEnd: saved current filter In the old filter, the end result is the old filter text: PanelLoad
filterInit: triggered
filterInit: applying old filter
filterEnd: triggered
filterEnd: saving current filter
filterEnd: saved current filter
filterInit: applied old filter So the new filter widget triggers Would triggering the search cause the second |
Ah, ok I see the problem now. When a search is triggered ( In the last update, I added two new widget functions, $('table')
.bind('filterInit', function () {
// check that storage utility is loaded
if ($.tablesorter.storage) {
// get saved filters
var f = $.tablesorter.storage( this, 'tablesorter-filters' ) || [];
$.tablesorter.setFilters( this, f, true );
}
})
.bind('filterEnd', function () {
if ($.tablesorter.storage) {
// save current filters
var f = $.tablesorter.getFilters( this );
$.tablesorter.storage( this, 'tablesorter-filters', f );
}
}); Here is the same demo with the console logs included. I'm still not sure why the |
Ahh, ok the triggered search "should" have updated the filter inputs, but it was a bug I didn't catch until now... it'll be fixed in the next update and the original code should start working properly as well. |
Hello,
I want to save/remember last filter data unless and until filter is reset using reset button.It should remember even after page refresh or coming back after visiting the page.
Any pointers to this kind of functionality will be helpful.
Regards,
Abhijit
The text was updated successfully, but these errors were encountered: