UI-Grid
UI-Grid 3.0 (formerly ng-grid) is a 100% Angular grid written with no dependencies other than AngularJS. It is designed around a core grid module and features are layered as Angular modules and Directives. This keeps the core; small and focused, while executing very complex features only when you need them.
In the core module, you get
- Virtualized rows and columns - only the rows and columns visible in the viewport (+ some extra margin) are actually rendered
- Bind cells to the complex properties and the functions.
- Column sorting with three states: Asc, Desc and None.
- Column filtering.
- Ability to change the header and the cell contents with the custom templates.
- i18nService allows label translations.
Prerequisites
Visual Studio 2015 is the prerequisite to work with this article.
Thus, let's just use the sections with which we can implement the functionality:
- Create ASP.NET MVC 5 Application.
- Adding Model.
- Scaffolding in MVC 5.
- View in MVC 5.
- Log in an Entity Framework.
Create ASP.NET MVC 5 Application
In this section, we'll create ASP.NET Web Application with the MVC 5 Project Template. Use the procedure given below.
Step 1
Open Visual Studio 2015 and click New Project.
Step 2
Select the Web from the left pane and create ASP.NET Web Application.
Step 3
Select the MVC Project Template in the next ASP.NET wizard.
Visual Studio automatically creates the MVC 5 Application, adds some files and folders to the solution.
Working with an Entity Framework
Follow the steps given below.
Step 1
Right click on Models folder, click Add New Item, select ADO.NET Entity Data Model from Data template and give a name.
Step 2
Select EF Designer from the database.
Step 3
Make a new connection and select a connection, if you already have a connection.
Step 4
Select tables, view, stored procedures and click Finish.
Now, create a new Web API controller with actions, using Entity Framework, as shown below.
Step 1
Right click on controller folder, click Add and select Controller.
Step 2
Select Web API Controller with actions, using Entity Framework.
Step 3
Select Model Class, Data context class, controller name and click Add.
You will get the code given below.
- using ng_ui_grid_sample.Models;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- using System.Linq;
- using System.Net;
- using System.Threading.Tasks;
- using System.Web.Http;
- using System.Web.Http.Description;
- namespace ng_ui_grid_sample.Controllers {
- public class EmployeesAPIController: ApiController {
- private NORTHWNDEntities db = new NORTHWNDEntities();
- // GET: api/Employees
- public IQueryable < Employees > GetEmployees() {
- return db.Employees;
- }
- // GET: api/Employees/5
- [ResponseType(typeof(Employees))]
- public async Task < IHttpActionResult > GetEmployees(int id) {
- Employees employees = await db.Employees.FindAsync(id);
- if (employees == null) {
- return NotFound();
- }
- return Ok(employees);
- }
- // PUT: api/Employees/5
- [ResponseType(typeof(void))]
- public async Task < IHttpActionResult > PutEmployees(int id, Employees employees) {
- if (!ModelState.IsValid) {
- return BadRequest(ModelState);
- }
- if (id != employees.EmployeeID) {
- return BadRequest();
- }
- db.Entry(employees).State = EntityState.Modified;
- try {
- await db.SaveChangesAsync();
- } catch (DbUpdateConcurrencyException) {
- if (!EmployeesExists(id)) {
- return NotFound();
- } else {
- throw;
- }
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- // POST: api/Employees
- [ResponseType(typeof(Employees))]
- public async Task < IHttpActionResult > PostEmployees(Employees employees) {
- if (!ModelState.IsValid) {
- return BadRequest(ModelState);
- }
- db.Employees.Add(employees);
- await db.SaveChangesAsync();
- return CreatedAtRoute("DefaultApi", new {
- id = employees.EmployeeID
- }, employees);
- }
- // DELETE: api/Employees/5
- [ResponseType(typeof(Employees))]
- public async Task < IHttpActionResult > DeleteEmployees(int id) {
- Employees employees = await db.Employees.FindAsync(id);
- if (employees == null) {
- return NotFound();
- }
- db.Employees.Remove(employees);
- await db.SaveChangesAsync();
- return Ok(employees);
- }
- protected override void Dispose(bool disposing) {
- if (disposing) {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- private bool EmployeesExists(int id) {
- return db.Employees.Count(e => e.EmployeeID == id) > 0;
- }
- }
- }




ankit dixitPosted Oct 9, 2020, 4:41 AM
Nice, Its Working but here common searching is not there.
Sankar MathiyazhaganPosted Feb 5, 2019, 12:11 PM
I have tried to implement angular ui grid , but grid is not loaded. could you pls help me on this
Amarkant SemwalPosted Dec 12, 2018, 11:40 PM
Can i export data using this grid?
Anurag SinhaPosted Jul 5, 2018, 4:14 AM
Hi Raj, I am getting 404 error for the API link http://localhost:6253/api/Employees
onais ahmerPosted Apr 10, 2018, 11:23 PM
Data shown in json format but not in ui.grid what the issue ??
onais ahmerPosted Apr 3, 2018, 6:07 AM
Can you provide some pictorial help ... I am doing this in Visual Studio 2013 MVC5 Api controller error occurs
Xuan DungPosted Nov 14, 2017, 10:27 PM
Please, can you send to me the full source code, I need study and learn about this problem, thank you very much. Email: [email protected]
Siddi Khadar ValiPosted Sep 20, 2017, 9:57 AM
HI Raj kumar, Thank you very much for the detailed Article. If possible could you please upload the source code of the articles.. I am new to MVC, Angular JS.. It is more helpful for me to find out what I am missing in my machine..I tried the steps mentioned in the article.. Thanks, Siddi.
Former memberPosted May 22, 2017, 5:19 AM
Why image is not showing in grid ?
Thiruppathi RPosted May 17, 2017, 12:08 AM
Nice article & UI grid works like as datatable?
Oyedepo OlufemiPosted May 7, 2017, 4:24 PM
Where's the index page going to be?
Saravanakumar SekaranPosted May 5, 2017, 10:27 PM
Wow great article with great explanation