Link to download Source code.
What is Gijgo?
Gijgo is a set of free open source JavaScript controls distributed under MIT License. All the widgets are high performance, built on top of the jQuery JavaScript library with built-in support for Bootstrap, Material Design, and Font Awesome. They are designed to save you time and scale with your development process.
Using jqGrid with ASP.NET MVC
If you have heard about jqGrid and you want to use it, have a look at a detailed article of it. I am sure you will love it.
Prerequisites for application
- Visual Studio 2012 / 2013 / 2015 / 2017
- Entity Framework 5 and above
- SQL Server 2008
Let’s start with the database part first.
Database Part
I have created a database with the name “Northwind” which has “Customers” table.

Next, we are going to create an ASP.NET MVC5 Web application.
Creating ASP.NET MVC5 Web Application
Open New Visual Studio 2015 IDE.

After opening IDE, next, we are going to create MVC project. For doing that, just click File - New - Project.

After choosing a project, a new dialog will pop up with the name “New Project”. In that, we are going to choose Visual C# Project Templates - Web - ASP.NET Web Application. Then, we are going to name the project as “DemoGijgo”.

After naming the project, click on OK button to create the project. A new dialog will pop up for choosing templates for creating “ASP.NET Web Application;”. In that template, we are going to create an MVC application. That's why we are going to choose “MVC template” and next, click on OK button to create the project.

After clicking on OK button, it will start to create a project.
Project Structure

After creating project, create Model.
Creating Customer Model
We are going to add Customer Model to the Models folder.

- [Table("Customers")]
- public class Customers
- {
- [Key]
- public int? CustomerID { get; set; }
- [Required(ErrorMessage = "Required CompanyName")]
- public string CompanyName { get; set; }
- [Required(ErrorMessage = "Required ContactName")]
- public string ContactName { get; set; }
- [Required(ErrorMessage = "Required ContactTitle")]
- public string ContactTitle { get; set; }
- public string Address { get; set; }
- [Required(ErrorMessage = "Required City")]
- public string City { get; set; }
- public string Region { get; set; }
- [Required(ErrorMessage = "Required PostalCode")]
- public string PostalCode { get; set; }
- [Required(ErrorMessage = "Required Country")]
- public string Country { get; set; }
- [Required(ErrorMessage = "Required Phone")]
- public string Phone { get; set; }
- public string Fax { get; set; }
- }
After adding model, we are going to use Entity framework for accessing the database. For that, we need to set up DbContext class.
Note - What is DbContext?
DbContext is an important part of Entity Framework. It is a bridge between your domain or entity classes and the database. DbContext is the primary class that is responsible for interacting with the data as an object.
Referenced from,
http://www.entityframeworktutorial.net/EntityFramework4.3/dbcontext-vs-objectcontext.aspx
Setting up DbContext Class
In this part, we are first going to create a class with name “DatabaseContext” and this class will be inheriting from “DbContext” class.
We are going to create this class in Models folder.

Note
“DBConnection” is Connection string name.
Note: - What is DBSet?
DBSet class represents an entity set that is used for creating, read, update, and delete operations. A generic version of DBSet (DbSet<TEntity>) can be used when the type of entity is not known at build time.
After adding “DatabaseContext” class, next, we are going to inherit this class with “DbContext” class.
After inheriting the class, in the constructor, we are going to create a connection. For doing that, we need to pass the connection string named as “DbContext” class. We are passing a connection string named as DBConnection.
After passing the connection string, we are going to declare DbSet in “DbContext” class which will help us to perform create, read, update, and delete operations.
Code Snippet
- using System.Data.Entity;
- namespace DemoGijgo.Models
- {
- public class DatabaseContext : DbContext
- {
- public DatabaseContext() : base("DBConnection")
- {
- }
- public DbSet<Customers> Customers { get; set; }
- }
- }
Connection string in Web.config file
- <connectionStrings>
- <addname="DBConnection"
- connectionString="Data Source=####; initial catalog=Northwind; user id=sa; password=Pass####;"
- providerName="System.Data.SqlClient" />
- </connectionStrings>
Next, we are going to add a controller.
Adding DemoController
In this part, we are going to add a new controller with name “Demo”.

Next, after adding Controller, we are going to get a Default Action method with name Index, we are going add this View for displaying Grid, along with that we need to add another Action Method for handling Ajax Get Request for Getting Data and binding it to Grid.
Adding Action Method GetCustomer
This Action Method will return a Json object that is required for binding data to gird.
Adding GetCustomers Action Method which will take few parameters as input for handling (sorting, Paging, and searching in the grid).
- public JsonResult GetCustomers(int? page, int? limit, string sortBy, string direction, string companyName, string contactName, string country)
- {
- List<Customers> records;
- int total;
- // step 1
- using (DatabaseContext context = new DatabaseContext())
- {
- // step 2
- var query = (from tempcustomer in context.Customers
- select tempcustomer);
- // step 3 applying where clause to linq query if companyName is not empty
- if (!string.IsNullOrWhiteSpace(companyName))
- {
- query = query.Where(q => q.CompanyName.Contains(companyName));
- }
- // step 4 applying where clause to linq query if contactName is not empty
- if (!string.IsNullOrWhiteSpace(contactName))
- {
- query = query.Where(q => q.ContactName != null && q.ContactName.Contains(contactName));
- }
- // step 5 applying where clause to linq query if country is not empty
- if (!string.IsNullOrWhiteSpace(country))
- {
- query = query.Where(q => q.Country != null && q.Country.Contains(country));
- }
- // step 6 applying sorting asc to (companyname,contactname,country,city)
- if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
- {
- if (direction.Trim().ToLower() == "asc")
- {
- switch (sortBy.Trim().ToLower())
- {
- case "companyname":
- query = query.OrderBy(q => q.CompanyName);
- break;
- case "contactname":
- query = query.OrderBy(q => q.ContactName);
- break;
- case "country":
- query = query.OrderBy(q => q.Country);
- break;
- case "city":
- query = query.OrderBy(q => q.City);
- break;
- }
- }
- else
- {
- // step 7 applying sorting desc (companyname,contactname,country,city)
- switch (sortBy.Trim().ToLower())
- {
- case "companyname":
- query = query.OrderByDescending(q => q.CompanyName);
- break;
- case "contactname":
- query = query.OrderByDescending(q => q.ContactName);
- break;
- case "country":
- query = query.OrderByDescending(q => q.Country);
- break;
- case "city":
- query = query.OrderByDescending(q => q.City);
- break;
- }
- }
- }
- else
- {
- query = query.OrderBy(q => q.CustomerID);
- }
- // step 8 Total rows count
- total = query.Count();
- // step 9 Paging
- if (page.HasValue && limit.HasValue)
- {
- int start = (page.Value - 1) * limit.Value;
- records = query.Skip(start).Take(limit.Value).ToList();
- }
- else
- {
- records = query.ToList();
- }
- }
- // step 10 returing json object
- return this.Json(new { records, total }, JsonRequestBehavior.AllowGet);
- }
Understanding Code Snippet in steps.
- In the first step, we create Instance of DatabaseContext for accessing Database.
- In the second step, we write Linq query for getting customer
- In the third step, the company name parameter which we going to receive from the grid when someone is going to search data with company name, after receiving, first, we are going to check is company name not empty after that we are going to apply where clause to Linq query of the company name.
- In the fourth step we are going apply a similar check on the contactName parameter and if it is not empty than we are going to apply where clause to Linq query of contactName.
- In fifth step we are going to apply the similar check to the country parameter and if it is not empty than we are going apply where clause to Linq query of the country.
- In the sixth step, we are going to apply sorting in ascending order for particular columns (company name, contact name, country, city) if someone has a requirement to add some more columns then they can add.
- In the seventh step, we are going to apply sorting in descending order for particular columns (company name, contact name, country, city) if someone has a requirement to add some more columns then they can add.
- In the eighth step, we are going calculate a total number of rows.
- In ninth step, we are going to apply paging logic
- In final step, we are going to return Json object which contains (customer records and total count of customers)
After adding and Understanding GetCustomer Action Method next we are going to add View for Index Action Method which was default created while creating Controller.
Adding Index View to Index Action Method
In this part, we are going to add Index View.

Project structure after adding Index view.

Adding Script and CSS reference of Gijgo Grid to Index View
In this step, we are going to add Script and CSS reference to index view.
- <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css" />
- <link href="https://cdnjs.cloudflare.com/ajax/libs/gijgo/1.7.0/combined/css/gijgo.min.css" rel="stylesheet" type="text/css" />
- <link href="http://code.gijgo.com/1.7.0/css/demo.css" rel="stylesheet" type="text/css" />
- <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/gijgo/1.7.0/combined/js/gijgo.min.js" type="text/javascript"></script>
Adding empty <table> element
After adding Scripts and Css next we need to add table element for reserve the place where the grid should be created.
- <div class="gj-margin-top-10">
- <table id="grid"></table>
- </div>
Next step we are going to show simple grid with Customers columns in it.
Creating Gijgo Grid
In this part, we are going to write a script to create Gijgo and to call Action Method “GetCustomers” to get data to bind to the grid.
Code Snippet
- <script type="text/javascript">
- $(document).ready(function () {
- grid = $('#grid').grid({
- primaryKey: 'CustomerID',
- dataSource: '/Demo/GetCustomers',
- columns: [
- { field: 'CustomerID', hidden: true },
- { field: 'CompanyName', sortable: true },
- { field: 'ContactName', sortable: true },
- { field: 'ContactTitle', sortable: false },
- { field: 'Country', sortable: true },
- { field: 'City', sortable: true },
- { field: 'PostalCode', sortable: false },
- { field: 'Phone', sortable: false }
- ]
- });
- });
- </script>
After setting up a script for creating Gijgo Grid next we are going to Save and Run the application to have the first look at grid how it looks.

Enabling Pager
To enable paging just we need to add a small property to the grid. In that, you can see limit property which we can set to display a number of records on the grid.
- pager: { limit: 5 }
Code Snippet
- <script type="text/javascript">
- $(document).ready(function () {
- grid = $('#grid').grid({
- primaryKey: 'CustomerID',
- dataSource: '/Demo/GetCustomers',
- columns: [
- { field: 'CustomerID', hidden: true },
- { field: 'CompanyName', sortable: true },
- { field: 'ContactName', sortable: true },
- { field: 'ContactTitle', sortable: false },
- { field: 'Country', sortable: true },
- { field: 'City', sortable: true },
- { field: 'PostalCode', sortable: false },
- { field: 'Phone', sortable: false }
- ],
- pager: { limit: 5 }
- });
- });
- </script>
Snapshot of paging

Debugging view after I change paging dropdown from 10 to 20.
Debugging view

After adding paging next, we need to add creating a new customer, editing customer, deleting customer and also we need to create a search for this grid.
Adding new Customer
In this part, we are going to create a new customer, and for doing that we need to create a dialog because when we are going to click on add new customer button a dialog will pop up and in that popup, we are going add details and click on save button to save details.
On the index, view we are going to add a button and a dialog box markup.
Markup for button
- <div class="gj-float-right">
- <button id="btnAdd" type="button" class="gj-button-md">Add New Customer</button>
- </div>
Markup for dialog
In this part you see that we have created a simple dialog using div tags and inside this tags we have added all textbox controls for taking input and this all controls name are similar to names of customer model, which helps in model binding.
Along with that, you can see two buttons in that; one for saving and the other for cancelling.
- <div id="dialog" class="gj-display-none">
- <div data-role="body">
- <input type="hidden" id="CustomerID"/>
- <div class="">
- <input type="text" class="gj-textbox-md" id="CompanyName" placeholder="CompanyName...">
- <input type="text" class="gj-textbox-md" id="ContactName" placeholder="ContactName...">
- <input type="text" class="gj-textbox-md" id="ContactTitle" placeholder="ContactTitle...">
- <input type="text" class="gj-textbox-md" id="Address" placeholder="Address...">
- <input type="text" class="gj-textbox-md" id="City" placeholder="City...">
- <input type="text" class="gj-textbox-md" id="Region" placeholder="Region...">
- <input type="text" class="gj-textbox-md" id="PostalCode" placeholder="PostalCode...">
- <input type="text" class="gj-textbox-md" id="Country" placeholder="Country...">
- <input type="text" class="gj-textbox-md" id="Phone" placeholder="Phone...">
- <input type="text" class="gj-textbox-md" id="Fax" placeholder="Fax...">
- </div>
- </div>
- <div data-role="footer">
- <button type="button" id="btnSave" class="gj-button-md">Save</button>
- <button type="button" id="btnCancel" class="gj-button-md">Cancel</button>
- </div>
- </div>
















Saineshwar BageriPosted May 15, 2019, 10:30 PM
Download example from this https://github.com/saineshwar/Gijgo-Grid-Example
Sourav Kumar DasPosted Dec 20, 2018, 1:13 AM
The project Execution it stopped and I don't know what it went wrong, but while building it showed 1 succeeded.
Sourav Kumar DasPosted Dec 20, 2018, 1:07 AM
Hi Sir, This project it ran and suddenly it stops and says that this site can't be reached.
lavanya sharmaPosted Apr 23, 2018, 3:48 AM
Nice explanation. It's helpful. I want to know how to export selected rows to excel.
tejesh gajulaPosted Mar 22, 2018, 7:25 AM
Hi Saineshwa, I have more than 20 columns to display in the grid. How can i get a horizontal scroll in gijmo grid.
Nabeel MahmoodPosted Feb 22, 2018, 1:45 AM
Thank you, but i want to add export to excel functionality, Can you pls guide?
Hernan MaldonadoPosted Feb 20, 2018, 2:32 AM
Thank you Saineshwar, how can add validation inbuilt without complex modification.
Tridip BhattacharjeePosted Jan 16, 2018, 6:50 AM
One request. please write a article on Grid.Mvc Grid.Mvc for edit and delete data.https://gridmvc.codeplex.com/
Baljit GrewalPosted Dec 21, 2017, 10:04 AM
What about Sorting?
Arvind SinghPosted Dec 20, 2017, 11:23 PM
Very nice article...........