Introduction to the Grid control for JavaScript | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (199)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (63)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (892)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (62)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (37)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (497)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (379)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (319)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

Introduction to the Grid control for JavaScript

By Yogesh R.

Introduction

The Grid control for JavaScript is a feature-rich control that provides extensive appearance customization options with support for grouped records. With the JavaScript Grid control, you can create a grid with a highly customizable look and feel. This grid is very useful for generating complex grid-based reports with rich formatting. It supports paging, sorting, grouping, filtering, and editing features.

Key Features

1. Paging

2. Sorting

3. Editing

4. Grouping

5. Filtering

6. Detail template

Getting Started

The basics for using the Grid control for JavaScript are provided in the sections below.

Grid Creation

1. Create an HTML file.

2. Paste the following template to the HTML file for the JavaScript Grid control.

<!DOCTYPE html>
<html>
<head>
<title>Getting Started with Essential JS</title>
<!-- Style sheet for default theme(flat azure). -->
<link href="http://cdn.syncfusion.com/js/flat-azure/ej.widgets.all-latest.min.css" rel="stylesheet" />
<!--scripts-->
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/globalize/0.1.1/globalize.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script src="http://cdn.syncfusion.com/js/ej.widgets.all-latest.min.js"></script>
</head>
<body>
//Add the grid element here.
</body>
</html>

3. Add the div element for grid rendering.

<div id="Grid"></div>

4. Initialize the Grid control with local data in the script.

$(function () {// Document ready. 
// Add data for grid here.
var data = [{ "OrderID": 10248, "CustomerID": "VINET", "EmployeeID": 5 },
{ "OrderID": 10249, "CustomerID": "TOMSP", "EmployeeID": 6 },
{ "OrderID": 10250, "CustomerID": "HANAR", "EmployeeID": 4 }];

// Simple control creation.

$("#Grid").ejGrid({
//array of json object
dataSource: data,
columns: [
{ field: "OrderID" },
{ field: "CustomerID" },
{ field: "EmployeeID" }
]
});
});

5. Output of above steps:

image

Data Binding

Remote Data

Control initialized with oData service.

$("#Grid").ejGrid(options);

options : <Object Literal>

Creates the control with the options provided.

Example:

$(function () {// Data for grid.
// Essential JS data manager for retrieving data from service
var dataManger = ej.DataManager({
url: "http://mvc.syncfusion.com/Services/Northwnd.svc/Orders/"
});

// Simple control creation.

$("#Grid").ejGrid({
dataSource: dataManager, // Essential JS data manager.
allowPaging: true,
columns: [
{ field: "OrderID" },
{ field: "CustomerID" },
{ field: "EmployeeID" }
]
});
});

Enabling basic features

Paging

Enable the paging feature after initializing.

$("#Grid").ejGrid("option", "allowPaging", true);
Sorting

Enable the sorting feature after initializing.

$("#Grid").ejGrid("option", "allowSorting", true);
Filtering

Enable the filtering feature after initializing.

$("#Grid").ejGrid("option", "allowFiltering", true);
Editing

Enable the editing feature at Grid initialize.

$("#Grid").ejGrid({
dataSource: data,
edit:{allowEditing:true},
columns: [
{ field: "OrderID",key:true },
{ field: "CustomerID" },
{ field: "EmployeeID" }
]
});

Wiring events

Events are important for providing notifications on the changes and actions that have happened in controls. The events can be wired the same way that jQuery events are bound. Event initialization of grid is as follows:

$("#Grid").ejGrid("model.eventName", <eventHandler>);

Or

$("#Grid").on("ejGrideventName”, <eventHandler>);

Bind the event “eventName” to control.

Example

$("#Grid").ejGrid({
dataSource: data,
queryCellInfo:function(args){
// event handler
},

columns: [
{ field: "OrderID" },
{ field: "CustomerID" },
{ field: "EmployeeID" }
]
});

$("#Grid").ejGrid("model.rowSelected", function () {
// event handler 
});

$("#Grid").on("ejGridrowSelected", function () {
// event handler 
});

Dependencies

Essential JS has dependency on the following libraries:

1. jQuery – 1.7.1 and above

2. JS Render – for templates

3. jQuery easing – for animation

4. jQuery Globalize – for globalization

You need to include all these references as script files in your projects.

Conclusion

In summary, you should be able to easily integrate Essential JS into your new or existing applications since it follows the same usage patterns as jQuery. We will also be posting blogs on our other JavaScript controls in the coming days.

For those who have not yet tried our Essential Studio for JavaScript, check out our complete list of controls, take a look at our online demos, or download a free evaluation today.

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed