Quick Start

Last updated: May 5th, 2017

ASP.NET Custom Grid

Razor view Grid Control

Thank you for purchasing Arthaus Custom Grid. If you have any questions that have not been answered below, or you didn't find the answer in our demo project, feel free to contact us via our CodeCanyon account.

Thanks again!

About "ASP.NET Custom Grid"

The purpose of this grid control is to help you with your data display in table view interface with paging, sorting and filtering. The grid control can be very useful tool for building admin report pages with huge number of data records. The component is using server side paging, sorting and filtering and any taken grid action is refreshing the page.

You will need previous ASP.NET MVC3 programming experience to be able to use this component.

System Requirements

Features

Here is a list of features that this custom grid control has:

  • Displaying data in table view, with easy css customization
  • Data Pagination with two different pager types (scroll view and numbers view)
  • Data Sorting
  • Data Search/Filtering with different type of filter options for numbers, string or date fields
  • Data formatting, by using the simple String.Format method
  • Multi-language
  • Custom html for each column, which allows you to add links, icons, javascript code in grid cells
  • Highly customizable
  • Compatible with all MVC versions

Screenshots

Usage Guide

Adding Grid Reference

The image below shows how to add a reference to the Arthaus CustomGrid component in your project.

CustomGrid Folder

Create a folder with name "CustomGrid". The folder needs to have write permissions so that CustomGrid.js is generated. Once it is generated you can remove the write permissions.

For multiple languages add "Language" folder inside the "CustomGrid" folder. There you can add a .json file for each supported language named according to the predefined CultureInfo names and identifiers accepted and used by CultureInfo Class in the System.Globalization namespace.

You can see a sample .json file here.

Including CSS and JavaScript Files

This is example of adding a required JavaScript and CSS files in your master template:

<link href="Content/CustomGrid.css" rel="stylesheet" type="text/css" />
<link href="Content/jquery-ui-1.8.12.custom.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>    
<script src="Scripts/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.contextMenu.js" type="text/javascript"></script>

Razor View - Code

The DrawGrid method which is drawing the grid has the following parameters:

  • gridID - (string, required) - The id of the grid.
  • model - (IEnumerable<dynamic>, required) - List of grid data rows.
  • columns - (CustomGridColumn, required) - A list of grid columns.
  • queryStringParams - (NameValueCollection, required) - Query string parameters.
  • action - (string, required) - Name of the action that will take care of the paging / sorting.
  • groupBy - (bool, optional) - If true, the grid will show the results grouped by the first column. Default is false.
  • searchBy - (bool, optional) - If true, search filter bar will be visible. Default is true.
  • tableCssClass - (string, optional) - Grid table css class. Default is "datatable".
  • dateFormat - (string, optional) - The format of the jQuery UI datepicker used in the grid filter. Default is "mm/dd/yy".

The Columns method is used for generating the grid columns and it has 6 overloads. Here is explained the most useful:

  • headerTitle - (string) - The visible title of the column in the grid.
  • html - (string) - The html string that will be used/replaced with the proper info.
  • fieldNames - (string[]) - String array of field names that we need.
  • sort - (bool, optional) - By default sorting is disabled. If enabled will sort by the first element in fieldNames array.
  • align - (string, optional) By default, the text is aligned left. Other supported alignments are right and center.

There are two paging methods that generate different type of paging (paging with scroll and paging with numbers), but both of those methods have the same parameters:

  • gridID - (string, required) - This is the id of the grid.
  • queryStringParams - (NameValueCollection, required) - Query string parameters.
  • totalRecords - (int, required) - Total number of records for display.
  • pageSize - (string, optional) - Number of records per page (provided as string).

Below is sample code for drawing a grid with different type of columns:

@CustomGrid.CustomGrid.DrawGrid("cl", Model,
	CustomGrid.CustomGrid.columns(
		CustomGrid.CustomGrid.column("First Name", "{0}", new string[] { "FirstName", "ID" }, true, "left", "text"),
		CustomGrid.CustomGrid.column("Last Name", "LastName", true, "left", "text"),
		CustomGrid.CustomGrid.column("Date Created", "{0:yyyy-MM-dd}", new string[] { "DateCreated" }, true, "left", "date"),             
		CustomGrid.CustomGrid.column("Decimal Value", "{0:c}", new string[] { "DoubleValue" }, true, "right", "number")
	), Request.QueryString)
@CustomGrid.CustomGrid.PagingNumbers("cl", Request.QueryString, ViewBag.totalRecords, "20")

Action Processor - Sample Code

This is just a sample code how you can fill your data collection with proper data by using LINQ approach with DynamicQueryable component from Mircrosoft and QueryParams from Arthaus. You can use any other code that you want, but have in mind that the grid is expecting as input data parameter to receive collection of data objects.

//database LINQ connection object defined in User model
SampleSQLDB db = new SampleSQLDB();

//get paging values from the query string
int pageNum = CustomGrid.QueryParams.getPageNumber("cl", Request.QueryString);
int pageSize = CustomGrid.QueryParams.getPageSize("cl", Request.QueryString);

//get sorting values from query string
string sort = CustomGrid.QueryParams.getSortField("cl", Request.QueryString, new User(), "ID");
string stype = CustomGrid.QueryParams.getSortType("cl", Request.QueryString);

//get filter where conditions and values from the query string
List<object> whereValues = new List<object>();
string whereConditions = "";
whereConditions += CustomGrid.QueryParams.getLINQQueryParam("cl", "ID", Request.QueryString, whereValues);
whereConditions += CustomGrid.QueryParams.getLINQQueryParam("cl", "FirstName", Request.QueryString, whereValues);
//... other where conditios 

//get data from database            
var sampleUser = db.Users.Select(i => i);
sampleUser = sampleUser.AsQueryable().Where("1=1 " + whereConditions, whereValues.ToArray()).OrderBy(sort + " " + stype);

//count the total number of records
ViewBag.totalRecords = sampleUser.Count();

//get only required page data by skiping the other records
sampleUser = sampleUser.Skip(pageSize * (pageNum - 1)).Take(pageSize);

return View(sampleUser.ToList());
									

Demo

Follow this link to see the grid in action! DEMO

Click here for detailed documentation.