function pre_render($data) { $rows = $_GET["jqgrid_page"] * $_GET["rows"]; $sidx = $_GET['sidx']; // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction // same sql as in select_command $rs = mysql_fetch_assoc(mysql_query("SELECT SUM(total) as s FROM (SELECT total FROM invheader ORDER BY $sidx $sord LIMIT $rows) AS tmp")); foreach($data["params"] as &$d) { $d["running_total"] = $rs["s"]; } }