Subselect and sum row
subselect() will create a new column with some value from other (or current) table. You can use any columns from current table as parameters. Subselect will be called for each row.
public function subselect_and_sum_row()
{
$xcrud = get_xcrud();
$xcrud->table('customers');
$xcrud->columns('customerName,city,creditLimit,Paid,Profit'); // specify only some columns
$xcrud->subselect('Paid','SELECT SUM(amount) FROM payments WHERE customerNumber = {customerNumber}'); // other table
$xcrud->subselect('Profit','{Paid}-{creditLimit}'); // current table
$xcrud->sum('creditLimit,Paid,Profit'); // sum row(), receives data from full table (ignores pagination)
$xcrud->change_type('Profit','price','0',array('prefix'=>'$')); // number format
$data['content'] = $xcrud->render();
return view('demos', $data);
}