Need to add columns with calculated data to server side processed table
Need to add columns with calculated data to server side processed table
brianfidler
Posts: 21Questions: 1Answers: 0
I have a table that is processed using the AJAX serverside processing. How can I add columns that take data from the database and calculate it to provide the result for that column.
for example:
Column 5 == "Assessed Home Value" value of current row: $100,000
Column 6 == "Market Home Value" value of current row: $88,000
Column 7 == "Dif between Assessed and Market" == (value of col5 current row) - (value of col6 current row) = $12,000
Column 8 == "Home Value at Zillow" value generated via an API call to Zillow
for example:
Column 5 == "Assessed Home Value" value of current row: $100,000
Column 6 == "Market Home Value" value of current row: $88,000
Column 7 == "Dif between Assessed and Market" == (value of col5 current row) - (value of col6 current row) = $12,000
Column 8 == "Home Value at Zillow" value generated via an API call to Zillow
This discussion has been closed.
Replies
1. Do it on the server-side (probably my preferred option, since you are getting the server to do the work), which will simply make the calculations you need and add them into the array returned. If you have a look here: http://datatables.net/development/server-side/php_mysql , it could be done at line 171.
2. Do it on the client-side - use fnRowCallback ( http://datatables.net/usage/callbacks#fnRowCallback ) to process each row as they come in (you'll need to have empty strings in the array for the columns which are to be calculated) and do the calculations.
Regards,
Allan
What exactly would I put at line 171?
Allan
So when I add that line it then gives me an error because my column count is off. I don't mean to be dense, but I just am right now. Here is the error i'm seeing...
DataTables warning (table id = 'foreclosuredata'): Added data (size 15) does not match known number of columns (14)
and it's based on my putting the following line just above the $output line.
[code]$row[] = $aRow[ 'ASSESVALUE' ] - 100;
$output['aaData'][] = $row;[/code]
So then I tried to add an additional column to my $aColumns by adding a space, so I took the following:
[code]$aColumns = array( 'PARCELNUMBER', 'PROPERTYADDRESS', 'PROPERTYCITY', 'PROPERTYZIP', 'SUBDIVISIN', 'SALEDATE', 'SALETIME', 'ASSESVALUE', 'LOTSIZE', 'POOLSIZE', 'HOMESQFT', 'YEARBLT', 'OPENBID', 'STATUS' );[/code]
and changed it to this:
[code]$aColumns = array( 'PARCELNUMBER', 'PROPERTYADDRESS', 'PROPERTYCITY', 'PROPERTYZIP', 'SUBDIVISIN', 'SALEDATE', 'SALETIME', 'ASSESVALUE', 'LOTSIZE', 'POOLSIZE', 'HOMESQFT', 'YEARBLT', 'OPENBID', 'STATUS', ' ' );[/code]
which then gave me this JSON parse error:
DataTables warning: JSON data from server failed to load or be parsed. This is most likely to be caused by a JSON formatting error.