mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Add pager documentation about processing & extra values. Fixes #576
This commit is contained in:
parent
bcefd5e004
commit
48d52edf58
@ -3012,7 +3012,36 @@ $.extend($.tablesorter.themes.jui, {
|
|||||||
// no need to trigger an update method, it's done internally
|
// no need to trigger an update method, it's done internally
|
||||||
return [ total ];
|
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" : '<tr><td>a123</td><td>abc</td><td>xyz</td><td>999</td></tr>',
|
||||||
|
"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>
|
||||||
<td><a href="example-pager-ajax.html">Example</a></td>
|
<td><a href="example-pager-ajax.html">Example</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user