1. Go to this page and download the library: Download daveawb/datatables library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$datatable->columns(array(
// Note the space as second arg to append
array("first_name", array("append" => "eats lots of pies, "))
));
// If value of first_name is David the output would be
array(
// Only the aaData values are shown here
"aaData" => array(
array(
"first_name" => "David eats lots of pies"
)
)
);
$datatable->columns(array(
// Note the space as second arg to prepend
array("last_name", array("prepend" => "Mr, "))
));
// If value of last_name is Barker the output would be
array(
// Only the aaData values are shown here
"aaData" => array(
array(
"last_name" => "Mr Barker"
)
)
);
$datatable->columns(array(
// Note the space as the last arg to combine
array("first_name", "last_name", array("combine" => "first_name,last_name, "))
));
array(
// Only the aaData values are shown here
"aaData" => array(
array(
"first_name" => "David Barker"
)
)
);
$datatable->columns(array(
array(
"first_name",
"last_name",
array(
"combine" => "first_name,last_name, ",
"append" => "Mr, ",
"prepend" => "BSc(hons), "
)
);
));
// The result of the above would be
array(
// Only the aaData values are shown here
"aaData" => array(
array(
"first_name" => "Mr David Barker BSc(hons)"
)
)
);
$datatable->columns(array(
array(
"first_name",
function($field, $databaseRowData)
{
return sprintf(
"A modified first_name field, it was %s before",
$databaseRowData->$field
);
}
);
));
// The result of the above would be
array(
"aaData" => array(
array(
"first_name" => "A modified first_name field, it was David before"
)
)
);