From 48d52edf5891111434e352b0c5230143be856e82 Mon Sep 17 00:00:00 2001 From: Mottie Date: Tue, 8 Apr 2014 18:53:01 -0500 Subject: [PATCH] Add pager documentation about processing & extra values. Fixes #576 --- docs/index.html | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 3c60f96c7..531592316 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3012,7 +3012,36 @@

Comparison example

// no need to trigger an update method, it's done internally return [ total ]; } -} +}In tablesorter v2.11, the ajaxProcessing function can return an object containing these properties, along with any extra properties. These extra properties will be available for use within the pager output string (see more details in issue #326);
+
+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 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. +
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;
+    }
+}
Now in the output string, you can also reference the extra ajax data: +
output : '{startRow} to {endRow} of {filtered_rows} ({totalRows}) rows about {subject} ({tasty})'
+ Example