4
\$\begingroup\$

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

\$\endgroup\$

    1 Answer 1

    1
    \$\begingroup\$

    I think your question is architectural in its nature, and it's rather hard to tell whether you want to prerender as much as you can on server side (meaning via PHP) or do most of the work on the client (i.e. via Angular.js). Each approach has its pros and cons.

    Here area fewsources that may help you form your opinion about whether to go

    • client-heavy (would be my default pick)
    • server-heavy
    • spread complexity across layers (I'm really not a fan of having bits and pieces of scattered business logic).

    To get a more definitive answer about which way to go, you would really need to provide the list of both functional and non-functional requirements to your system.

    \$\endgroup\$

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.