I am using DataTables to format and display a table. I started the project using AngularJS with a PHP backend but I needed to inject some Vanilla JS and JQuery code in order to use DataTables.
Is this approach/organization fine, or should I be trying to use AngularJS modules like ngTable to keep the project "pure".
AngularJS + JQuery snippet for pulling data in DataTable
$http.post('requests.php', data, config).then(
function(response) {
var df = response.data['data'];
// Put data into table
$("#UserTable").DataTable( {
pagingType: "full_numbers",
processing : true,
data: df,
order: [[ 0, "desc" ]],
columns:
[
{ data: "user" },
{ data: "name" }
]
} );
});
PHP BACKEND
if (isset($params['req']) && $params['req'] == "users") {
$json = array();
foreach ($cma_DB->query($sql) as $row) {
// MAKE ARRAY ASSOCIATIVE; THIS WAS BROKEN IN OTHER VERSIONS OF DATATABLES
$json[] = array(
'user' => $row['user'],
'name' => $row['first_name'] . " " . $row['last_name']
);
}
// MAKE RESPONSE HAVE 'data' ENTRY //
$response = array();
$response['success'] = true;
$response['data'] = $json;
echo json_encode($response);
}
VERSUS
Something written using ngTable