i using angularjs call sql query , return whole table. there way manipulate data on front end once i've retrieved data or better manipulation on processing page before gets angular?
the code below shows app.js file using retrieve data , have included line of html show sample of type of output trying achieve.
app.js
var dashboardapp = angular.module('dashboardapp', []); dashboardapp.controller('dashboardcontroller', function($scope, $http, $location, $anchorscroll) { $http.get('lib/dbp.php').success(function(data) { $scope.surveydata = data; }); }); sample html
<ul> <li ng-repeat="item in surveydata['data']">{{item.location}}</li> </ul> {{surveydata['data'].location.length}} sample output
{ "data": [ { "surveyid": "51", "customername": "steve jones", "companyname": "acme", "projectname": "various project", "customerphone": "", "customeremail": "", "location": "dallas", "q1": "1", "q1comment": "none", "q2": "1", "q2comment": "none", "q3": "1", "q3comment": "none", "q4": "2", "q4comment": "none", "q5": "1", "q5comment": "none", "q6": "yes", "q6comment": "always.", "q7": "yes", "q7comment": "always.", "q8": "yes", "q8comment": "certainly.", "q9": "yes", "q9comment": "none", "q10comment": "none", "q11comment": "keep work!", "q12": "no", "timestamp": "2015-07-17 11:08:24", "ipaddress": "" } the ng-repeat section works fine basic data output location.length i'd able count number of locations individually, i.e. zone 1 has 5 surveys submitted or zone 2 has 8.
i new angularjs trying figure out best practice type of situation.
what see output count of records location of "dallas" or average of scores records "dallas". there numerous other things having grasp on how simple data manipulation mentioned me other applications of data.
using sql query return entire table not typically practice. it's acceptable if guaranteed have small table forever (a strong statement). otherwise it's best target queries whatever data presented, , use second query high-level information count.
i don't know backend looks like, typical approach (pseudocode):
data = {} select surveyid, customername, ... "yourtable" (...) limit 48 offset 0; response -> data.rows = response select count(*) "yourtable" (...); response -> data.count = response return data then on frontend you're manipulating { rows: [...], count: 123 }, should in format want given needs above.
Comments
Post a Comment