In my application I am using Jquery table sorter and pager.I need to do server side pagination
using this pager's ajaxURL and ajaxProcessing options.I am using server side language as coldfusion. When I call a cfc method using this ajaxUrl option in pager I am getting "Uncaugh error :OK[200]"in the table cell.
Here is the code that I am using
=================================
$(document).ready(function() {
$("#myTable")
.tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({
container: $(".pager"),
ajaxUrl:'userdetails.cfc?method=getUserDetails&page={page}&size={size}',
ajaxObject: {
dataType: 'json'
},
ajaxProcessing: function(data, table, xhr){alert(data.hasOwnProperty('rows'));
if (data && data.hasOwnProperty('rows')) {
var r, row, c, d = data.rows,
// total number of rows (required)
total = data.total_rows,
// array of header names (optional)
headers = data.cols,
// all rows: array of arrays; each internal array has the table cell data for that row
rows = [],
// len should match pager set size (c.size)
len = d.length;
// this will depend on how the json is set up - see City0.json
// rows
for ( r = 0; r < len; r++ ) {
row = []; // new row array
// cells
for ( c in d[r] ) {
if (typeof(c) === "string") {
row.push(d[r][c]); // add each table cell data to row array
}
}
rows.push(row); // add new row array to rows array
}
return [ total, rows, headers ]; // or return [ rows, total, headers ] in v2.9+
}
},
output: '{startRow} to {endRow} ({totalRows})',
page:1
});
});
Server side code
===============
<cfcomponent>
<cffunction name="getUserDetails" access="remote" returntype="any">
<cfargument name="page" type="string" required="true">
<cfargument name="size" type="string" required="true">
<cfsavecontent variable="rdata">
{ "total_rows": 80, "cols" : [ "username", "password" ], "rows" : [{ "username": 1, "password": "Kabul" } ,{ "username": 2, "password": "Kabul2" }]}
</cfsavecontent>
<cfreturn rdata>
</cffunction>
</cfcomponent>