{"id":12408,"date":"2016-01-11T14:41:00","date_gmt":"2016-01-11T14:41:00","guid":{"rendered":"https:\/\/viewmyprojects.com\/winwirewp\/?p=12408"},"modified":"2023-11-30T11:11:29","modified_gmt":"2023-11-30T11:11:29","slug":"angular-js-basics-ng-grid-features-part-1","status":"publish","type":"post","link":"https:\/\/viewmyprojects.com\/winwirewp\/blog\/angular-js-basics-ng-grid-features-part-1\/","title":{"rendered":"Angular JS \u2013 Basics \u2013 ng-grid features \u2013 Part 1"},"content":{"rendered":"\n<p>Ng-grid is 100% angular grid which has no dependencies other than angular js. It has pagination, sorting, filtering and local data model binding\/editing built in allowing for quick and easy integration with any Angular JS application.<\/p>\n\n\n\n<p>In this post we will demonstrate few ng-grid features by using REST API over HTTP.<br>To get started we have add below references:<br>1. Angular JS<br>2. JQuery<br>3. Ng-Grid JS and CSS files<\/p>\n\n\n\n<p><strong>Steps to get data from REST API over HTTP and data binding to ng-grid<\/strong><\/p>\n\n\n\n<p><strong>HTML<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"681\" height=\"161\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr1.webp\" alt=\"\" class=\"wp-image-18885\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr1.webp 681w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr1-300x71.webp 300w\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" \/><\/figure><\/div>\n\n\n<p><strong>JS<\/strong><\/p>\n\n\n\n<p>1. Declare your app module and add ng-grid<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"417\" height=\"37\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr2.webp\" alt=\"\" class=\"wp-image-18884\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr2.webp 417w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr2-300x27.webp 300w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/figure><\/div>\n\n\n<p>2. Assign controller to your app module<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"478\" height=\"48\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr3-1.webp\" alt=\"\" class=\"wp-image-18883\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr3-1.webp 478w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr3-1-300x30.webp 300w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/figure><\/div>\n\n\n<p>3. Script that returns JSON object from API using HTTP. Here am querying SharePoint list \u201cEmployeeDetails\u201d and retrieving values from 4 columns EmployeeID, EmployeeName, Department, ProfilePic.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"795\" height=\"142\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr4.webp\" alt=\"\" class=\"wp-image-18882\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr4.webp 795w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr4-300x54.webp 300w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr4-768x137.webp 768w\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" \/><\/figure><\/div>\n\n\n<p>4. Now initialize grid options under same controller as data. This binds the data to grid.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"203\" height=\"73\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr5.webp\" alt=\"\" class=\"wp-image-18880\"\/><\/figure><\/div>\n\n\n<p>5. To bind only specific columns, we can define column definitions in ng-grid as below. It is common requirement for any Grid to have column names (display name) different from JSON name. Let\u2019s bind only 4 columns which are retrieved from list.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"791\" height=\"292\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr6.webp\" alt=\"\" class=\"wp-image-18881\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr6.webp 791w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr6-300x111.webp 300w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr6-768x284.webp 768w\" sizes=\"auto, (max-width: 791px) 100vw, 791px\" \/><\/figure><\/div>\n\n\n<p><strong>OUTPUT<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"162\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr7.webp\" alt=\"\" class=\"wp-image-18879\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr7.webp 488w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr7-300x100.webp 300w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/figure><\/div>\n\n\n<p><strong>Pagination<\/strong><\/p>\n\n\n\n<p>When pagination is enabled, data is displayed in pages that can be browsed using built in pagination selector. Lets build simple pagination.<\/p>\n\n\n\n<p>To define page size and index,<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"554\" height=\"204\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr8.webp\" alt=\"\" class=\"wp-image-18878\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr8.webp 554w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr8-300x110.webp 300w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"121\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr9.webp\" alt=\"\" class=\"wp-image-18877\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr9.webp 726w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr9-300x50.webp 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/figure><\/div>\n\n\n<p>To bind data when page is changed, we have to make http call in PagedDataAsync method,<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"198\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr10.webp\" alt=\"\" class=\"wp-image-18876\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr10.webp 788w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr10-300x75.webp 300w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr10-768x193.webp 768w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/figure><\/div>\n\n\n<p>Finally while binding data, we have to enable pagination<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"348\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr11.webp\" alt=\"\" class=\"wp-image-18875\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr11.webp 786w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr11-300x133.webp 300w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr11-768x340.webp 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n<p><strong>OUTPUT<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"468\" height=\"248\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr12.webp\" alt=\"\" class=\"wp-image-18873\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr12.webp 468w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr12-300x159.webp 300w\" sizes=\"auto, (max-width: 468px) 100vw, 468px\" \/><\/figure><\/div>\n\n\n<p><strong>Sorting<\/strong><\/p>\n\n\n\n<p>Sorting is \u2018ON\u2019 by default. You can set enableSorting flag in gridOptions to enable\/disable it.<br>Sorting can also be disabled at column level by setting enableSorting : false in column definition<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"791\" height=\"364\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr13.webp\" alt=\"\" class=\"wp-image-18874\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr13.webp 791w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr13-300x138.webp 300w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr13-768x353.webp 768w\" sizes=\"auto, (max-width: 791px) 100vw, 791px\" \/><\/figure><\/div>\n\n\n<p><strong>OUTPUT<\/strong><br><strong>Sorted by EmployeeName<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"254\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr14.webp\" alt=\"\" class=\"wp-image-18872\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr14.webp 470w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/sr14-300x162.webp 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"170\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Sruti1.webp\" alt=\"\" class=\"wp-image-18887\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Sruti1.webp 467w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Sruti1-300x109.webp 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/figure><\/div>","protected":false},"excerpt":{"rendered":"<p>Ng-grid is 100% angular grid which has no dependencies other than angular js. It has pagination, sorting, filtering and local data model binding\/editing built in allowing for quick and easy integration with any Angular JS application. In this post we will demonstrate few ng-grid features by using REST API over HTTP.To get started we have&hellip; <a class=\"more-link\" href=\"https:\/\/viewmyprojects.com\/winwirewp\/blog\/angular-js-basics-ng-grid-features-part-1\/\">Continue reading <span class=\"screen-reader-text\">Angular JS \u2013 Basics \u2013 ng-grid features \u2013 Part 1<\/span><\/a><\/p>\n","protected":false},"author":63,"featured_media":16817,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-12408","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","entry"],"acf":[],"featured_image_src":"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic.webp","author_info":{"display_name":"Sruthi","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/sruthi\/"},"views":3607,"uagb_featured_image_src":{"full":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic.webp",800,440,false],"thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic-150x150.webp",150,150,true],"medium":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic-300x165.webp",300,165,true],"medium_large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic-768x422.webp",750,412,true],"large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic.webp",750,413,false],"1536x1536":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic.webp",800,440,false],"2048x2048":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic.webp",800,440,false],"post-thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Angular-JS-Basics-ng-grid-features-Part-1-graphic.webp",800,440,false]},"uagb_author_info":{"display_name":"Sruthi","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/sruthi\/"},"uagb_comment_info":0,"uagb_excerpt":"Ng-grid is 100% angular grid which has no dependencies other than angular js. It has pagination, sorting, filtering and local data model binding\/editing built in allowing for quick and easy integration with any Angular JS application. In this post we will demonstrate few ng-grid features by using REST API over HTTP.To get started we have&hellip;&hellip;","_links":{"self":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/12408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/comments?post=12408"}],"version-history":[{"count":2,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/12408\/revisions"}],"predecessor-version":[{"id":18888,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/12408\/revisions\/18888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media\/16817"}],"wp:attachment":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media?parent=12408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/categories?post=12408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/tags?post=12408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}