-
Notifications
You must be signed in to change notification settings - Fork 755
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
Updating page selector and row count information when using ajax #649
Comments
Hi @lindonb! I'm not sure why all of that extra coding is needed, the pager plugin/widget should have been doing those calculations all along. I set up these demos (plugin / widget) using the filter and pager. Filter any column and the filtered rows value and page selector will change. Also, the |
Thanks @Mottie, I agree with you and all works fine when not iusing Ajax, but in my case I am using Ajax. The information on number of rows and the page selector aren't updating for me correctly when using Ajax unless I add extra coding. |
Wow, sorry, I totally misread your question; sorry I've been very busy lately, and distracted. The Now if you want to display the correct filter row count, this should also be returned from the server. If you look at the documentation for the So, lets say the data sent by the server looks like this: {
"total_rows" : 100,
"filtered_rows" : 75,
"new_headers" : [ "ID", "Name", "Data", "Value" ],
"data" : '<tr><td>a123</td><td>abc</td><td>xyz</td><td>999</td></tr>',
"subject" : "cheese",
"tasty" : "It's delicious!"
} This pager_ajaxProcessing: function(result, table, xhr){
if (result && result.hasOwnProperty('data')) {
// "total" is a required property!
result.total = result["total_rows"];
// "headers" is optional. This is not needed if the table headers don't change
result.headers = result["new_headers"];
// "rows" is optional. No need to return this if you process and add the rows
// to the table yourself otherwise, return an array of arrays or jQuery object
// (shown in this example)
result.rows = $(result.data);
return result;
}
} Now in the output string, you can also reference the extra ajax data:
I hope that is what you need. |
Thanks @Mottie, that's very helpful for the |
Hmm, yeah, I guess it would be better to have the |
Try the update I just pushed to the working branch.... when the |
Many many thanks @Mottie - works beautifully and saves me a lot of extra code! |
Spotted one remaining issue - when the filter causes no records to be found, neither the |
I can't seem to target the code that might be causing this issue. Are you sure that your server is returning data, including a |
Yes, the data seems to be returned including a p.filteredRows = result.filteredRows || result.total; The above properly sets |
Ahh, ok, that makes sense. Try the update to the working branch and see if that fixes it. |
That fixes it! I noticed that the Thanks again for all your help on this! |
Ok, smashed that bug too! :P |
Confirmed smash! Thanks again. |
When applying a filter and using ajax, I use code within
pager_ajaxProcessing
and in a separate function outside of tablesorter to create the values needed to show the proper row information (e.g., "1-25 / 80 (80)") and the page selector dropdown. Is there an easier way to supply the needed values to tablesorter so that the end values are generated automatically within tablesorter as they are when ajax is not used?Here's what I currently do: I return the start row and filtered number of rows in the HTML. In
pager_ajaxProcessing
I extract and manipulate those values to calculate the end row, start row and number of filtered pages and create the text for thepager_output
option.Since the
gotoPage
selector doesn't automatically update, I use another function outside of tablesorter to rebuild the page selector from scratch to show the proper number of pages based on the filtered results.I set this up a while back and I know a lot of great changes have been made, so I could have missed the fact that this extra coding is no longer necessary. Thanks for any help.
The text was updated successfully, but these errors were encountered: