SlideShare a Scribd company logo
Part 1: ng-grid and a Simple REST API 
It is a common requirement for any project to display data in 
some kind of tabular format. The easiest way to achieve this is 
by using HTML table. But soon this gets complex as you need a 
way to support pagination (client-side and server-side), sorting 
(single & multi column), resizable columns, inline editing, 
ˉOWHULQJHWF 
Options 
• HTML Table 
• JQuery Grid Plugins (jqGrid, FlexGrid etc.) 
• Angular’s native implementation of Grid 
• ng-grid 
• ng-table 
First Grid Solution 
7KHˉUVWVROXWLRQZHDUHJRLQJWRORRNDWLVng-grid which is built for AngularJS 
and is the most popular Grid solution out there for Angular. 
www.backand.com
Where to Start 
In this Blog post we will build a grid solution using Angular and ng-grid, 
which hooks in to the RESTful end point running locally using NodeJS  
ExpressJS. We will use basic features of Node  Express. Before jumping 
in, you may want to see the working code on Plunker: http://embed.plnkr. 
co/865hnS/preview. 
Assumptions 
1. You already know AngularJS 
2. Know the basics of Grunt, Bower and Bootstrap 
3. Have basic knowledge about REST 
4. You already have node, npm, git and bower installed on your development 
machine 
Project Structure 
We will use the following Angular seed project: 
https://github.com/libertyleap/angular-grunt-seed 
This is the seed project which comes with a default bower and grunt build for 
lint, karma, watch, livereload, express server, etc. 
Steps to setup  run Seed Project: 
1. Clone the project: 
 git clone https://github.com/libertyleap/angular-grunt-seed.git 
2. Rename the project from angular-grunt-seed to ng-grid-demo 
 mv angular-grunt-seed ng-grid-demo 
3. Change the current directory to ng-grid-demo 
 cd ng-grid-demo 
4. Execute npm install so that all the Grunt dependencies are downloaded 
and it also runs bower install 
 npm install 
5. Execute grunt, this will start the local Node server on port 9000. 
 grunt 
www.backand.com
6. Open your favorite browser and go to: http://localhost:9000/ 
Adding NG-Grid into Seed Project Using Bower 
The easiest way to add ng-grid to seed project is using Bower and we will 
cover this approach in this blog. If you are not comfortable doing this, you can 
do it manually i.e. go to ng-grid repo: http://angular-ui.github.io/ng-grid/ and 
FRSRYHUWKHUHTXLUHGˉOHVZKLFKDUHFRYHUHGEHORZ 
 bower install ng-grid –save-dev 
Above command updates the ng-grid-demobower.jsonˉOHWRDGGng-grid as 
dependency. 
Bower will download ng-grid locally. You can verify this by going in to the 
“bower-components” folder. You will see a new folder ng-grid inside the 
bower-components folder. 
Hooking-up NG-Grid with View Restful Service 
To utilize ng-grid in our seed project we need to reference two ng-grid 
ˉOHV7KHˉUVWRQHLVWKH-DYDVFULSWˉOHDQGWKHVHFRQGLVWKH66IRUWKH 
WKHPLQJRIWKHJULG7KHˉUVWVWHSZLOOEHWRJRLQWRRXUindex.htmlˉOH 
DQGDGGERWKWKH-DYD6FULSWDQGWKHFVVˉOHVDVGHSHQGHQF 
www.backand.com
Open the ng-grid-demo/src/index.htmlˉOHDQGDGGWKHIROORZLQJHQWULHV 
1. In the head add this css dependency (bower-components/ng-grid/ng-grid. 
www.backand.com 
css). 
2. In the body section add ng-grid’s js dependency (bower-components/ 
ng-grid/ng-grid-2.0.12.debug.js). 
3. We need to add the ‘ngGrid’ Angular module dependency to app.js so that 
we can start using ng-grid’s directives and other services. 
NG-Grid Basic Example 
We will look at the steps required to add the basic ng-grid example in this 
section. We will explore ng-grid’s advanced features in coming sections. 
To be able to demonstrate grid features we need some kind of REST endpoint. 
)RUWKLVEORJSRVWZHZLOOXVHORFDO-621ˉOHDV5(67HQGSRLQWZKLFKZLOO 
serve list of open source contributors. 
REST  JSON: 
Create a folder json XQGHU QJJULGGHPR?VUF IROGHU UHDWH D QHZ MVRQ ˉOH 
FDOOHGFRQWULEXWRUVMVRQ7KLV-621ˉOHZLOOKDYHWKHIROORZLQJFRQWHQWZKLFK 
will be served to UI  ng-grid.
ng-grid-demosrcjsoncontributor.json 
KDQJHWKH*UXQWEXLOGWRLQFOXGHWKLVMVRQˉOHLQ .build directory. 
Angular Factory: 
Let’s create a service (gridService.js) that will return above JSON using REST’s 
GET method. This data will be returned asynchronously and we will use 
Promises ($q) for this. Here is the Service code. 
We will have one method called getContributors which will use Angular’s 
$http (https://docs.angularjs.org/api/ng/service/$http) to get the data from 
MVRQFRQWULEXWRUVMVRQˉOH,WDOVRXVHV$QJXODUȠVSURPLVHLPSOHPHQWDWLRQT 
(https://docs.angularjs.org/api/ng/service/$q). 
www.backand.com
This is what is happening here: 
• When controller calls this factory method “getContributors” it will get a 
promise object back i.e. deferred.promise. 
• When response comes back from the asynchronous $http call we will 
resolve deferred object to return list of contributors. 
• If there is an error in $http then we will reject the deferred object with 
the reason so that caller can handle it appropriately i.e. show some kind 
of message back to user. 
Controller: 
We will add “GridService” as a dependency to “HomeController” and call 
“getContributors” method from GridService. Response is set as “myData” which 
will be used to populate ng-grid data in view. 
The above step $scope.gridOptions is the main setup which hooks-up ng-grid 
FRQˉJXUDWLRQWRQJJULGȠVYLHZ 
View: 
6HWWLQJXSWKHJULGLQRXU+70/ˉOHLVUHDOOHDVDQGMXVWUHTXLUHVFUHDWLQJD 
div, and adding a ng-grid directive to it with the parameter being the function 
in the controller that we will create soon. We are also going to add a simple 
class onto the div for easy styling. Change “templateshome.html” to include 
the following code: 
Here “gridOptions” is $scope object populated in controller. 
This should get the basic ng-grid up and running. 
www.backand.com
NG-Grid Features 
,QWKLVVHFWLRQZHZLOOH[SORUHGLIIHUHQWFRQˉJXUDWLRQRSWLRQVIRUQJJULG:H 
just need to change $scope.gridOptions in Controller to be able to support 
the following features. 
ROXPQ'HˉQLWLRQ 
It is a common requirement for any Grid to name column names different 
IURPWKH-621QDPH2QHH[DPSOHDERYHLVZHZDQWWRQDPHȢˉUVWQDPHȣWR 
“First Name”. 
Cell Template Example: 
%HORZLVDQH[DPSOHRQKRZWRGHˉQHFHOOWHPSODWHVXVLQJVWULQJVLQQJJULG 
From the above example we want to apply Green color to id column with id 
 1. 
In-line Cell Editing Example: 
We will explore an option to be able to edit the Grid cell and save it to the 
REST service. We will demonstrate code to be able to update the “company” 
cell of the contributor in Grid. 
www.backand.com
homeController.js 
We need to set enableCellEditSURSHUWWR758(IRUWKHFROXPQGHˉQLWLRQ 
After setting this if you restart the node server you will see company column 
is editable after double clicking the cell. 
The next step is we want to send this updated cell info to REST backend. For 
this we will use one of ng-grid’s Event (ngGridEventEndCellEdit), which will 
broadcast after cell is edited. You can see all the available ng-grid’s Events 
here: https://github.com/angular-ui/ng-grid/wiki/Grid-Events 
We will update the controller to have the following code 
As you can see from the above code we want to send the updated row 
LQIRUPDWLRQ EDFN WR 5(67 VHUYLFH :H QHHG WR GHˉQH D QHZ PHWKRG 
saveContributor in our gridService.js. 
www.backand.com 
gridService.js
We do not have a real REST service and it is impossible to demo this as we 
need some kind of persistent store. You can open your browser’s developer 
tools and validate above $http post method is called with the right data. 
You can see completed code for this blog here: https://github.com/backand/ 
ng-grid-rest-simple-demo. And stay tuned for Part 2 of this series when we 
cover ng-grid and a real REST API. 
References 
Blog Code: https://github.com/backand/ng-grid-rest-simple-demo 
Plunker: http://embed.plnkr.co/865hnS/preview 
ng-grid documentation: http://angular-ui.github.io/ng-grid/ 
ng-grid code: https://github.com/angular-ui/ng-grid 
www.backand.com 
Contact Information 
Backand Inc. 
info@backand.com 
www.backand.com

More Related Content

What's hot

The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196
Mahmoud Samir Fayed
 
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Docker and Your Path to a Better Staging Environment - webinar by Gil TayarDocker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Applitools
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
Schalk Cronjé
 
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
Robert Cooper
 
Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0
David Chandler
 
The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202
Mahmoud Samir Fayed
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
Johannes Weber
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speed
Fate Chang
 
Angular
AngularAngular
Angular
sridhiya
 
Guice gin
Guice ginGuice gin
Guice gin
Robert Cooper
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
Igor Khotin
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
KAI CHU CHUNG
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
KAI CHU CHUNG
 
Springを用いた社内ライブラリ開発
Springを用いた社内ライブラリ開発Springを用いた社内ライブラリ開発
Springを用いた社内ライブラリ開発
Recruit Lifestyle Co., Ltd.
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
Mike North
 
Hands on the Gradle
Hands on the GradleHands on the Gradle
Hands on the Gradle
Matthias Käppler
 
Improving the Accumulo User Experience
 Improving the Accumulo User Experience Improving the Accumulo User Experience
Improving the Accumulo User Experience
Accumulo Summit
 
Intro
IntroIntro
Intro
bspremo
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016
Alvaro Sanchez-Mariscal
 
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試
Simon Su
 

What's hot (20)

The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196
 
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Docker and Your Path to a Better Staging Environment - webinar by Gil TayarDocker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
 
Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0
 
The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speed
 
Angular
AngularAngular
Angular
 
Guice gin
Guice ginGuice gin
Guice gin
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
 
Springを用いた社内ライブラリ開発
Springを用いた社内ライブラリ開発Springを用いた社内ライブラリ開発
Springを用いた社内ライブラリ開発
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
 
Hands on the Gradle
Hands on the GradleHands on the Gradle
Hands on the Gradle
 
Improving the Accumulo User Experience
 Improving the Accumulo User Experience Improving the Accumulo User Experience
Improving the Accumulo User Experience
 
Intro
IntroIntro
Intro
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016
 
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試
 

Viewers also liked

Start an Angular project fast, then go faster using AWS and Back&
Start an Angular project fast, then go faster using AWS and Back&Start an Angular project fast, then go faster using AWS and Back&
Start an Angular project fast, then go faster using AWS and Back&
Backand Cohen
 
Documentació ALES (fi de curs)
Documentació ALES (fi de curs)Documentació ALES (fi de curs)
Documentació ALES (fi de curs)AlesPinetons2013
 
NK_resume_final
NK_resume_finalNK_resume_final
NK_resume_final
Naveen Kumar
 
Growth Hacking - UX
Growth Hacking - UXGrowth Hacking - UX
Growth Hacking - UX
Somia Customer Experience
 
Creative salon_0630_WORLD CUP 2014 AD
Creative salon_0630_WORLD CUP 2014 ADCreative salon_0630_WORLD CUP 2014 AD
Creative salon_0630_WORLD CUP 2014 ADMPCDU
 
Creative salon_0807_CANNES LIONS 2014
Creative salon_0807_CANNES LIONS 2014Creative salon_0807_CANNES LIONS 2014
Creative salon_0807_CANNES LIONS 2014
MPCDU
 
Outwards and Inwards Experiential Transformation - Kaskus Case Study
Outwards and Inwards Experiential Transformation - Kaskus Case StudyOutwards and Inwards Experiential Transformation - Kaskus Case Study
Outwards and Inwards Experiential Transformation - Kaskus Case Study
Somia Customer Experience
 
The State of UX Profession in Indonesia, July 2016
The State of UX Profession in Indonesia, July 2016The State of UX Profession in Indonesia, July 2016
The State of UX Profession in Indonesia, July 2016
Somia Customer Experience
 
DIY UX Audit
DIY UX AuditDIY UX Audit

Viewers also liked (9)

Start an Angular project fast, then go faster using AWS and Back&
Start an Angular project fast, then go faster using AWS and Back&Start an Angular project fast, then go faster using AWS and Back&
Start an Angular project fast, then go faster using AWS and Back&
 
Documentació ALES (fi de curs)
Documentació ALES (fi de curs)Documentació ALES (fi de curs)
Documentació ALES (fi de curs)
 
NK_resume_final
NK_resume_finalNK_resume_final
NK_resume_final
 
Growth Hacking - UX
Growth Hacking - UXGrowth Hacking - UX
Growth Hacking - UX
 
Creative salon_0630_WORLD CUP 2014 AD
Creative salon_0630_WORLD CUP 2014 ADCreative salon_0630_WORLD CUP 2014 AD
Creative salon_0630_WORLD CUP 2014 AD
 
Creative salon_0807_CANNES LIONS 2014
Creative salon_0807_CANNES LIONS 2014Creative salon_0807_CANNES LIONS 2014
Creative salon_0807_CANNES LIONS 2014
 
Outwards and Inwards Experiential Transformation - Kaskus Case Study
Outwards and Inwards Experiential Transformation - Kaskus Case StudyOutwards and Inwards Experiential Transformation - Kaskus Case Study
Outwards and Inwards Experiential Transformation - Kaskus Case Study
 
The State of UX Profession in Indonesia, July 2016
The State of UX Profession in Indonesia, July 2016The State of UX Profession in Indonesia, July 2016
The State of UX Profession in Indonesia, July 2016
 
DIY UX Audit
DIY UX AuditDIY UX Audit
DIY UX Audit
 

Similar to ng-grid and a Simple REST API

AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
Eric Wise
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
marpierc
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
Dev_Events
 
DevFest 2022 - Skaffold 2 Deep Dive Taipei.pdf
DevFest 2022 - Skaffold 2 Deep Dive Taipei.pdfDevFest 2022 - Skaffold 2 Deep Dive Taipei.pdf
DevFest 2022 - Skaffold 2 Deep Dive Taipei.pdf
KAI CHU CHUNG
 
Grails & Angular: unleashing the dynamic duo
Grails & Angular: unleashing the dynamic duoGrails & Angular: unleashing the dynamic duo
Grails & Angular: unleashing the dynamic duo
Rubén Mondéjar Andreu
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
William Marques
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
أحمد عبد الوهاب
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
Andrei Sebastian Cîmpean
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
Angular js
Angular jsAngular js
Angular js
Behind D Walls
 
GCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdf
GCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdfGCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdf
GCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdf
ssuserc36624
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
Presentation on angular 5
Presentation on angular 5Presentation on angular 5
Presentation on angular 5
Ramesh Adhikari
 
Angular js
Angular jsAngular js
Angular js
Thyda Eng
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
Sashko Stubailo
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Knoldus Inc.
 
The Ring programming language version 1.9 book - Part 81 of 210
The Ring programming language version 1.9 book - Part 81 of 210The Ring programming language version 1.9 book - Part 81 of 210
The Ring programming language version 1.9 book - Part 81 of 210
Mahmoud Samir Fayed
 
202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP
Ronald Hsu
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
Saurabh Dixit
 

Similar to ng-grid and a Simple REST API (20)

AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
 
DevFest 2022 - Skaffold 2 Deep Dive Taipei.pdf
DevFest 2022 - Skaffold 2 Deep Dive Taipei.pdfDevFest 2022 - Skaffold 2 Deep Dive Taipei.pdf
DevFest 2022 - Skaffold 2 Deep Dive Taipei.pdf
 
Grails & Angular: unleashing the dynamic duo
Grails & Angular: unleashing the dynamic duoGrails & Angular: unleashing the dynamic duo
Grails & Angular: unleashing the dynamic duo
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angular js
Angular jsAngular js
Angular js
 
GCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdf
GCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdfGCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdf
GCP-Professional-Cloud-Developer-Exam-v22.2.1_139-taqwlj.pdf
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
Presentation on angular 5
Presentation on angular 5Presentation on angular 5
Presentation on angular 5
 
Angular js
Angular jsAngular js
Angular js
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
The Ring programming language version 1.9 book - Part 81 of 210
The Ring programming language version 1.9 book - Part 81 of 210The Ring programming language version 1.9 book - Part 81 of 210
The Ring programming language version 1.9 book - Part 81 of 210
 
202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
 

More from Backand Cohen

Five Common Angular Mistakes
Five Common Angular MistakesFive Common Angular Mistakes
Five Common Angular Mistakes
Backand Cohen
 
How to Build Dynamic Forms in Angular Directive with a Backend
How to Build Dynamic Forms in Angular Directive with a BackendHow to Build Dynamic Forms in Angular Directive with a Backend
How to Build Dynamic Forms in Angular Directive with a Backend
Backand Cohen
 
REST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD ExampleREST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD Example
Backand Cohen
 
Testing Two-Way Data Binding in AngularJS
Testing Two-Way Data Binding in AngularJSTesting Two-Way Data Binding in AngularJS
Testing Two-Way Data Binding in AngularJS
Backand Cohen
 
Backand Presentation
Backand PresentationBackand Presentation
Backand Presentation
Backand Cohen
 
AngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkAngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro Framework
Backand Cohen
 
How-to Increase User Engagement by 25% with User Segmented Push Notifications
How-to Increase User Engagement by 25% with User Segmented Push NotificationsHow-to Increase User Engagement by 25% with User Segmented Push Notifications
How-to Increase User Engagement by 25% with User Segmented Push Notifications
Backand Cohen
 
The Enterprise Excel Hell
The Enterprise Excel HellThe Enterprise Excel Hell
The Enterprise Excel Hell
Backand Cohen
 

More from Backand Cohen (8)

Five Common Angular Mistakes
Five Common Angular MistakesFive Common Angular Mistakes
Five Common Angular Mistakes
 
How to Build Dynamic Forms in Angular Directive with a Backend
How to Build Dynamic Forms in Angular Directive with a BackendHow to Build Dynamic Forms in Angular Directive with a Backend
How to Build Dynamic Forms in Angular Directive with a Backend
 
REST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD ExampleREST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD Example
 
Testing Two-Way Data Binding in AngularJS
Testing Two-Way Data Binding in AngularJSTesting Two-Way Data Binding in AngularJS
Testing Two-Way Data Binding in AngularJS
 
Backand Presentation
Backand PresentationBackand Presentation
Backand Presentation
 
AngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkAngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro Framework
 
How-to Increase User Engagement by 25% with User Segmented Push Notifications
How-to Increase User Engagement by 25% with User Segmented Push NotificationsHow-to Increase User Engagement by 25% with User Segmented Push Notifications
How-to Increase User Engagement by 25% with User Segmented Push Notifications
 
The Enterprise Excel Hell
The Enterprise Excel HellThe Enterprise Excel Hell
The Enterprise Excel Hell
 

Recently uploaded

National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 

Recently uploaded (20)

National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 

ng-grid and a Simple REST API

  • 1. Part 1: ng-grid and a Simple REST API It is a common requirement for any project to display data in some kind of tabular format. The easiest way to achieve this is by using HTML table. But soon this gets complex as you need a way to support pagination (client-side and server-side), sorting (single & multi column), resizable columns, inline editing, ˉOWHULQJHWF Options • HTML Table • JQuery Grid Plugins (jqGrid, FlexGrid etc.) • Angular’s native implementation of Grid • ng-grid • ng-table First Grid Solution 7KHˉUVWVROXWLRQZHDUHJRLQJWRORRNDWLVng-grid which is built for AngularJS and is the most popular Grid solution out there for Angular. www.backand.com
  • 2. Where to Start In this Blog post we will build a grid solution using Angular and ng-grid, which hooks in to the RESTful end point running locally using NodeJS ExpressJS. We will use basic features of Node Express. Before jumping in, you may want to see the working code on Plunker: http://embed.plnkr. co/865hnS/preview. Assumptions 1. You already know AngularJS 2. Know the basics of Grunt, Bower and Bootstrap 3. Have basic knowledge about REST 4. You already have node, npm, git and bower installed on your development machine Project Structure We will use the following Angular seed project: https://github.com/libertyleap/angular-grunt-seed This is the seed project which comes with a default bower and grunt build for lint, karma, watch, livereload, express server, etc. Steps to setup run Seed Project: 1. Clone the project: git clone https://github.com/libertyleap/angular-grunt-seed.git 2. Rename the project from angular-grunt-seed to ng-grid-demo mv angular-grunt-seed ng-grid-demo 3. Change the current directory to ng-grid-demo cd ng-grid-demo 4. Execute npm install so that all the Grunt dependencies are downloaded and it also runs bower install npm install 5. Execute grunt, this will start the local Node server on port 9000. grunt www.backand.com
  • 3. 6. Open your favorite browser and go to: http://localhost:9000/ Adding NG-Grid into Seed Project Using Bower The easiest way to add ng-grid to seed project is using Bower and we will cover this approach in this blog. If you are not comfortable doing this, you can do it manually i.e. go to ng-grid repo: http://angular-ui.github.io/ng-grid/ and FRSRYHUWKHUHTXLUHGˉOHVZKLFKDUHFRYHUHGEHORZ bower install ng-grid –save-dev Above command updates the ng-grid-demobower.jsonˉOHWRDGGng-grid as dependency. Bower will download ng-grid locally. You can verify this by going in to the “bower-components” folder. You will see a new folder ng-grid inside the bower-components folder. Hooking-up NG-Grid with View Restful Service To utilize ng-grid in our seed project we need to reference two ng-grid ˉOHV7KHˉUVWRQHLVWKH-DYDVFULSWˉOHDQGWKHVHFRQGLVWKH66IRUWKH WKHPLQJRIWKHJULG7KHˉUVWVWHSZLOOEHWRJRLQWRRXUindex.htmlˉOH DQGDGGERWKWKH-DYD6FULSWDQGWKHFVVˉOHVDVGHSHQGHQF www.backand.com
  • 4. Open the ng-grid-demo/src/index.htmlˉOHDQGDGGWKHIROORZLQJHQWULHV 1. In the head add this css dependency (bower-components/ng-grid/ng-grid. www.backand.com css). 2. In the body section add ng-grid’s js dependency (bower-components/ ng-grid/ng-grid-2.0.12.debug.js). 3. We need to add the ‘ngGrid’ Angular module dependency to app.js so that we can start using ng-grid’s directives and other services. NG-Grid Basic Example We will look at the steps required to add the basic ng-grid example in this section. We will explore ng-grid’s advanced features in coming sections. To be able to demonstrate grid features we need some kind of REST endpoint. )RUWKLVEORJSRVWZHZLOOXVHORFDO-621ˉOHDV5(67HQGSRLQWZKLFKZLOO serve list of open source contributors. REST JSON: Create a folder json XQGHU QJJULGGHPR?VUF IROGHU UHDWH D QHZ MVRQ ˉOH FDOOHGFRQWULEXWRUVMVRQ7KLV-621ˉOHZLOOKDYHWKHIROORZLQJFRQWHQWZKLFK will be served to UI ng-grid.
  • 5. ng-grid-demosrcjsoncontributor.json KDQJHWKH*UXQWEXLOGWRLQFOXGHWKLVMVRQˉOHLQ .build directory. Angular Factory: Let’s create a service (gridService.js) that will return above JSON using REST’s GET method. This data will be returned asynchronously and we will use Promises ($q) for this. Here is the Service code. We will have one method called getContributors which will use Angular’s $http (https://docs.angularjs.org/api/ng/service/$http) to get the data from MVRQFRQWULEXWRUVMVRQˉOH,WDOVRXVHV$QJXODUȠVSURPLVHLPSOHPHQWDWLRQT (https://docs.angularjs.org/api/ng/service/$q). www.backand.com
  • 6. This is what is happening here: • When controller calls this factory method “getContributors” it will get a promise object back i.e. deferred.promise. • When response comes back from the asynchronous $http call we will resolve deferred object to return list of contributors. • If there is an error in $http then we will reject the deferred object with the reason so that caller can handle it appropriately i.e. show some kind of message back to user. Controller: We will add “GridService” as a dependency to “HomeController” and call “getContributors” method from GridService. Response is set as “myData” which will be used to populate ng-grid data in view. The above step $scope.gridOptions is the main setup which hooks-up ng-grid FRQˉJXUDWLRQWRQJJULGȠVYLHZ View: 6HWWLQJXSWKHJULGLQRXU+70/ˉOHLVUHDOOHDVDQGMXVWUHTXLUHVFUHDWLQJD div, and adding a ng-grid directive to it with the parameter being the function in the controller that we will create soon. We are also going to add a simple class onto the div for easy styling. Change “templateshome.html” to include the following code: Here “gridOptions” is $scope object populated in controller. This should get the basic ng-grid up and running. www.backand.com
  • 7. NG-Grid Features ,QWKLVVHFWLRQZHZLOOH[SORUHGLIIHUHQWFRQˉJXUDWLRQRSWLRQVIRUQJJULG:H just need to change $scope.gridOptions in Controller to be able to support the following features. ROXPQ'HˉQLWLRQ It is a common requirement for any Grid to name column names different IURPWKH-621QDPH2QHH[DPSOHDERYHLVZHZDQWWRQDPHȢˉUVWQDPHȣWR “First Name”. Cell Template Example: %HORZLVDQH[DPSOHRQKRZWRGHˉQHFHOOWHPSODWHVXVLQJVWULQJVLQQJJULG From the above example we want to apply Green color to id column with id 1. In-line Cell Editing Example: We will explore an option to be able to edit the Grid cell and save it to the REST service. We will demonstrate code to be able to update the “company” cell of the contributor in Grid. www.backand.com
  • 8. homeController.js We need to set enableCellEditSURSHUWWR758(IRUWKHFROXPQGHˉQLWLRQ After setting this if you restart the node server you will see company column is editable after double clicking the cell. The next step is we want to send this updated cell info to REST backend. For this we will use one of ng-grid’s Event (ngGridEventEndCellEdit), which will broadcast after cell is edited. You can see all the available ng-grid’s Events here: https://github.com/angular-ui/ng-grid/wiki/Grid-Events We will update the controller to have the following code As you can see from the above code we want to send the updated row LQIRUPDWLRQ EDFN WR 5(67 VHUYLFH :H QHHG WR GHˉQH D QHZ PHWKRG saveContributor in our gridService.js. www.backand.com gridService.js
  • 9. We do not have a real REST service and it is impossible to demo this as we need some kind of persistent store. You can open your browser’s developer tools and validate above $http post method is called with the right data. You can see completed code for this blog here: https://github.com/backand/ ng-grid-rest-simple-demo. And stay tuned for Part 2 of this series when we cover ng-grid and a real REST API. References Blog Code: https://github.com/backand/ng-grid-rest-simple-demo Plunker: http://embed.plnkr.co/865hnS/preview ng-grid documentation: http://angular-ui.github.io/ng-grid/ ng-grid code: https://github.com/angular-ui/ng-grid www.backand.com Contact Information Backand Inc. info@backand.com www.backand.com