Issues with Pager AJAX and Filtering.
Lynesth opened this issue · 8 comments
Hello,
I haven't seen this issue posted before so I hope I didn't miss it. And excuse my poor english as it isn't my mothertongue (feel free to ask anything I may have not explained well enough).
Here is what's happening :
- I have a a small table with 10 rows (ajax returned).
- I use the filter to end up having 0 rows (since my PHP script is returning 0 total rows and an empty rows json).
- Table isn't updating to show that there's no row.
I had to change the ajaxProcessing function to check if the total number of rows returned is more than 0, otherwise return [ 0, " " ];
I think you'll better understand with this :
228 ajaxProcessing: function(data) {
229 if (data && data.hasOwnProperty('rows')) {
230 var r, row, c, d = data.rows,
231 // total number of rows (required)
232 total = data.total_rows;
233 if (total > 0) {
234 var rows = []
235 len = d.length;
236 for ( r=0; r < len; r++ ) {
237 row = [];
238 for ( c in d[r] ) {
239 if (typeof(c) === "string") {
240 row.push(d[r][c]);
241 }
242 }
243 rows.push(row);
244 }
245 return [ total, rows ];
246 } else {
247 return [ 0, " " ];
248 }
249 }
250 }
Couldn't it be a simple feature of the plugin ? Or am I really stupid and missing something ?
On another note, I was having issues when I was on the last page of a table and then filter it. Since I was getting much less total_rows (so much less pages) but the {page} sent to the PHP script was still the same and therefore it was unable to return any rows.
So is this the rigth way to make sure that the pager will be returning to the first page everytime the table gets filtered (still talking about ajax here) ?
256 .bind('filterStart', function(){
257 $(this).trigger('pageSet', 0);
258 });
I'm really not sure I made myself clear enough, but I hope so.
thank you for this awesome fork of tablesorter which is very handy 👍 !
Lyn.
Hi @Lynesth!
You have excellent English skills :)
Both of the issues you mention above do sound like problems with the code. I will put them on my to-do list.
Hello @Mottie !
Thank you for the English skills comment :)
Here is what I changed in jquery.tablesorter.pager.js to take care of the first "issue" :
274 d = p.totalRows == 0 ? " " : result[t ? 0 : 1] || []; // row data
Though you could also be a bit more precise and write down something like "No match found." like you do when you catch an exception.
I'm not that good with JS either so that might be just a little workaround but at least, it works for me :p
Hi @Lynesth!
Thanks for sharing your code changes!
I was thinking that for the second issue, should the page always be set to the first? Currently, it should stay on the current page if the current page is not less than the filtered pages, and go to the last page if the current page is greater. If that isn't working as it should, I don't see a problem with setting the page back to the first. Should this be an option, or do you think there would ever be a case that someone would not want to go back to the first page?
Hmmm...
I don't see a reason I would not go back to first page on filter.
How is it working without ajax if current page is greater than total pages ? I think I saw in your code it's setting the page to the last one, is that right ?
+1 to going back to first page after filtering. Could make it optional but
I also can't think of when I wouldn't want to be back on the first page.
Regards,
lindon
On Wed, Dec 11, 2013 at 5:51 PM, Rob G notifications@github.com wrote:
Hi @Lynesth https://github.com/Lynesth!
Thanks for sharing your code changes!
I was thinking that for the second issue, should the page always be set to
the first? Currently, it should stay on the current page if the current
page is not less than the filtered pages, and go to the last page if the
current page is greater. If that isn't working as it should, I don't see a
problem with setting the page back to the first. Should this be an option,
or do you think there would ever be a case that someone would not want to
go back to the first page?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/456#issuecomment-30372818
.
when you filter a dataset.. the amount of items/pages would change. thus the current item/page counts should be re-calculated.. and yes back to the first page.
Ok, both of these issues will be fixed in the next update.
Cool thing thank you ;)