Effective Ways to Utilize Responsiveness Angular Grid | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)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  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)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  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

Effective Ways to Utilize Responsiveness Angular Grid

Responsiveness is an approach to shrink web pages based on device width. This technique plays a key role in modern web applications to help users view the most important parts of a web page and to simplify interaction in different form factors. As per a Statista report, mobile phone and tablet users are increasing rapidly year by year. This report clearly shows that responsiveness is going to be an important factor in developing web applications.

In web applications, a grid is a vital component for displaying data in a tabular structure, but achieving responsiveness in a grid is cumbersome. Fortunately, the Syncfusion Angular grid component provides built-in responsive support.

Note: All the features and information in this blog are applicable to our other Essential JS 2 frameworks for React, Vue, ASP.NET Core, ASP.NET MVC, and JavaScript.

In this blog, we are going to explain how to utilize the responsiveness feature of the Angular grid. Before starting, you can download a starter grid sample from this GitHub repository and also check out this overview blog.

Before starting

To download the sample from GitHub, use the following command.

git clone https://github.com/SyncfusionSamples/ej2-angular-grid-simple.git
cd ej2-angular-grid-simple

Once all the files are downloaded, you can install packages related to Angular and the grid by using the following command.

npm install

Built-in responsive features

From the initial stage of development, we focused on giving all features in the grid a responsive nature. The grid has many advanced features such as sorting, paging, filtering, grouping, CRUD, virtual scrolling, and more. These advanced features are responsive in nature and work very well on different devices.

 

 

Angular grid on Desktop device


Angular grid on Tablet device

Angular grid on Mobile device

In the previous images, you can clearly see how the grid adapts to different form factors. In desktop view, the grid adapts with a horizontal layout and occupies the entire parent width along with the pager. In tablet view, a horizontal scroll bar is provided to make the grid more readable, and the pager’s design is changed to include previous and next buttons. The same occurs for mobile view: the grid and its pager adapt to a small view. You can check out the responsiveness of different features in our Angular grid by visiting our grid demos on different devices.

Hiding columns based on browser width

In our responsive grid technique, one of the most commonly used approaches is hiding columns based on browser width. For this, first we have to mark priority for individual columns. After that, we need to define CSS to hide columns in Media Queries. In our Essential JS 2 grid, we have simplified this approach and introduced a new property called hideAtMedia which accepts Media Queries once the given condition is satisfied. The grid will then hide the specified columns.

In the cloned demo application, we are going to define hideAtMedia with (min-width: 700px) for the Freight column as shown in the following file, grid.component.html. After that, if we resize the browser below 700 pixels, then the specified columns will be hidden.

  
  <ejs-grid [dataSource]='data' [allowPaging]='true' [allowSorting]='true'[allowFiltering]='true'
   [allowGrouping]='true' [filterSettings]='filterSettings' [pageSettings]="pageSettings">
    <e-columns>
      <e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
      <e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
      <e-column field='Freight' textAlign='Right' format='c2' hideAtMedia='(min-width: 700px)' width=120></e-column>
      <e-column field='CustomerName' headerText='Customer Name' hideAtMedia='(min-width: 500px)' width=120></e-column>
      <e-column field='ShipCountry' headerText='Ship Country'  width=120></e-column>
    </e-columns>
  </ejs-grid>

Grid in browser with width greater than 700 px


Grid in browser with width less than 700 px

Adapt within parent container

Sometimes we will have scenarios where we need to place the entire grid inside a parent element without affecting its height and width; for example, placing the grid inside a card component in dashboard applications. To do this, we need to define the height and width for the parent container and then define the grid height and width as 100%. In the following code sample, we define the parent container for app-grid in app.component.html.

 

Here we have defined width and height as 100% in grid.component.html.

  <ejs-grid [dataSource]='data' [allowPaging]='true' [allowSorting]='true' width='100%' height='100%' [allowFiltering]='true'
   [allowGrouping]='true' [filterSettings]='filterSettings' [pageSettings]="pageSettings">
    <e-columns>
      <e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
      <e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
      <e-column field='Freight' textAlign='Right' format='c2' hideAtMedia='(min-width: 700px)' width=120></e-column>
      <e-column field='CustomerName' headerText='Customer Name' hideAtMedia='(min-width: 500px)' width=120></e-column>
      <e-column field='ShipCountry' headerText='Ship Country'  width=120></e-column>
    </e-columns>
  </ejs-grid>  

After applying the parent container, the grid will adapt to its container.

Grid within parent container

Summary

In this blog we looked at the built-in responsive features and common responsive techniques in our Essential JS 2 grid component, such as hiding columns based on browser width and adapting to fit a parent container. These details will be helpful when developing an application with responsiveness in mind. Also, you can check out the responsive behavior explained in this blog in our GitHub repository, which is readily runnable.

Want to check out other features of our Angular grid? Visit the Angular grid component features page, the source in GitHub, other demos, and our documentation to explore more live samples of its features and API.

If you have any questions, please let us know in the comments section below. You can also contact us through our support forum or Direct-Trac. We are happy to assist you!

If you like this blog post, we think you’ll also like the following free e-books:

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed