Add pager documentation about processing & extra values. Fixes #576

This commit is contained in:
Mottie 2014-04-08 18:53:01 -05:00
parent bcefd5e004
commit 48d52edf58

View File

@ -3012,7 +3012,36 @@ $.extend($.tablesorter.themes.jui, {
// no need to trigger an update method, it's done internally
return [ total ];
}
}</pre></div>
}</pre>In tablesorter <span class="version">v2.11</span>, the <code>ajaxProcessing</code> function can return an object containing these properties, along with any extra properties. These extra properties will be available for use within the pager <code>output</code> string (see more details in <a href="https://github.com/Mottie/tablesorter/issues/326#issuecomment-25326546">issue #326</a>);<br>
<br>
So, lets say the data sent by the server looks like this:
<pre class="prettyprint lang-js">{
"total_rows" : 100,
"filtered_rows" : 75,
"new_headers" : [ "ID", "Name", "Data", "Value" ],
"data" : '&lt;tr&gt;&lt;td&gt;a123&lt;/td&gt;&lt;td&gt;abc&lt;/td&gt;&lt;td&gt;xyz&lt;/td&gt;&lt;td&gt;999&lt;/td&gt;&lt;/tr&gt;',
"subject" : "cheese",
"tasty" : "It's delicious!"
}</pre>
This ajaxProcessing function must return an object with "total", "headers" and "rows" properties! As before, "total" is the only required property; if the headers don't need to be changed, don't return a headers array, and if you append the rows to the table yourself within the ajaxProcessing function, you don't need to return a "rows" property.
<pre class="prettyprint lang-js">ajaxProcessing: function(result, table){
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;
}
}</pre>Now in the <a href="#pager-output"><code>output</code></a> string, you can also reference the extra ajax data:
<pre class="prettyprint lang-js">output : '{startRow} to {endRow} of {filtered_rows} ({totalRows}) rows about {subject} ({tasty})'</pre>
</div>
</td>
<td><a href="example-pager-ajax.html">Example</a></td>
</tr>