In this article, I have explained how to use Infragistics UI Data Grid (igGrid) in SharePoint online.

Introduction

In most cases, we use jQuery data table for data binding because it’s free of cost with awesome features. Nowadays, several data grids are available in the market for free or at a minimal cost with most enhanced features to play against the data, like Sorting, Paging, Filtering, and exporting to files like PDF, Excel. However, the most important thing is the performance and I am choosing this Infragistics UI data grid because I love its performance of binding the data in a fraction of second when comparing to the jQuery data table.

What Is igGrid?

igGrid is a jQuery grid that binds the data and has the following features.

Some of the dependencies are required for using the igGrid.

Now, open the SharePoint online data to create a data source for pulling the data from the SharePoint custom list.

For example, we are going to create a Product list to hold the product information, like ProductId, ProductName, Category, Stock etc. I have pushed some dummy data up to 5000 items in SharePoint list.

Ignite UI Data grid

Open SharePoint Designer -> Site Assets and create Igid.html file into it. Open the HTML file in a text editor to add the following references in the <head></head> Section.

  1. <!-- Ignite UI Required Combined CSS Files -->
  2. <link href="https://cdn-na.infragistics.com/igniteui/2017.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
  3. <link href="https://cdn-na.infragistics.com/igniteui/2017.2/latest/css/structure/infragistics.css" rel="stylesheet" />
  4. <script src="https://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
  5. <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  6. <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
  7. <!-- Ignite UI Required Combined JavaScript Files -->
  8. <script src="https://cdn-na.infragistics.com/igniteui/2017.2/latest/js/infragistics.core.js"></script>
  9. <script src="https://cdn-na.infragistics.com/igniteui/2017.2/latest/js/infragistics.lob.js"></script>

Create an AJAX request to fetch the data from SharePoint list. Add the HTML into the <body></body> tag.

  1. <table id="grid"></table>

Declare the necessary variables.

  1. <script>
  2. $(function() {
  3. var datas;
  4. var results = [];
  5. $.ajax({
  6. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('accessoriesdata')/items?$top=5000",
  7. method: "GET",
  8. headers: {
  9. "Accept": "application/json; odata=verbose"
  10. },
  11. success: function(data) {
  12. datas = data.d.results;
  13. console.log(datas);
  14. },
  15. error: function(error) {
  16. console.log(JSON.stringify(error));
  17. }
  18. });
  19. });
  20. </script>

In the browser console, you are now able to see how many records we retrieved in that AJAX Call.

Ignite UI Data grid

I have just formatted a data source like this.

  1. var result = [
  2. { "ProductID": 1, "ProductName": "Adjustable Race", "Category": "AR-5381", “Stock”:”” }
  3. ]

Code

  1. results.push({ "ProductID": datas[i].ID,
  2. "ProductName": datas[i].ProductName,
  3. "Category":datas[i].Category,
  4. "Stock":datas[i].Stock
  5. });
  6. console.log(results);

Result

Ignite UI Data grid

Now, in the next step, go and initialize the igGrid function of the table.

  1. function initigGrid(value){
  2. //Initialize the grid
  3. $("#grid").igGrid({
  4. autoGenerateColumns: false,
  5. //Define the columns and it’s datatypes
  6. columns: [
  7. { headerText: "Product ID", key: "ProductID", dataType: "number" },
  8. { headerText: "Product Name", key: "ProductName", dataType: "string" },
  9. { headerText: "Category", key: "Category", dataType: "string" },
  10. { headerText: "Stock", key: "Stock", dataType: "number" }
  11. ],
  12. //Pick the datasource to display
  13. dataSource: value
  14. });
  15. }

The overall script looks like below.

  1. <script>
  2. $(function() {
  3. var datas;
  4. var results = [];
  5. $.ajax({
  6. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('accessoriesdata')/items?$top=5000",
  7. method: "GET",
  8. headers: {
  9. "Accept": "application/json; odata=verbose"
  10. },
  11. success: function(data) {
  12. datas = data.d.results;
  13. console.log(datas);
  14. // Iterate through the data
  15. for(i=0; i < datas.length; i++)
  16. {
  17. results.push({ "ProductID": datas[i].ProductID,
  18. "ProductName": datas[i].Title,
  19. "Category":datas[i].Category,
  20. "Stock":datas[i].Stock
  21. });
  22. }
  23. console.log(results);
  24. initigGrid(results); //Call the function after successful results
  25. },
  26. error: function(error) {
  27. console.log(JSON.stringify(error));
  28. }
  29. });
  30. });
  31. function initigGrid(value){
  32. $("#grid").igGrid({
  33. autoGenerateColumns: false,
  34. columns: [
  35. { headerText: "Product ID", key: "ProductID", dataType: "number" },
  36. { headerText: "Product Name", key: "ProductName", dataType: "string" },
  37. { headerText: "Category", key: "Category", dataType: "string" },
  38. { headerText: "Stock", key: "Stock", dataType: "number" }
  39. ],
  40. dataSource: value
  41. });
  42. }
  43. </script>

Result

Ignite UI Data grid

Ignite UI Data grid

It’s showing 5000 items from the SharePoint list without paging. Now, I am going to show how to hide the column “ProductID”.

Just set the hidden attribute to true inside the column object. You can also format the width and height of the column.

  1. columns: [
  2. { headerText: "Product ID", key: "ProductID", dataType: "number" , hidden: true }
  3. ]

Ignite UI Data grid

Paging

Paging allows you to show the number of items per page. You can navigate to next and previous to next items.

Code

Features

  1. {
  2. name: "Paging", // It defines the paging feature
  3. pageSize: 10 // Mention the page size it view 10 per page now
  4. }

Ignite UI Data grid
Sorting

This feature allows you to sort the data in the columns. It also supports single and multi-column sorting.

  1. features: [
  2. {
  3. name: "Sorting", // Define sorting feature
  4. type: "local" // Type of sorting example local, remote
  5. }
  6. ]

Ignite UI Data grid
Filter

It helps to filter the data based on the conditions; for example - Equals, Not equals, contains etc.

Code

  1. {
  2. name: "Filtering", // Define filter feature
  3. type: "local", // Type of filter
  4. columnSettings: [
  5. {
  6. // If you do not want to filter some column, just set allowFiltering: false
  7. // By default, other columns are set to true.
  8. columnKey: "ProductName",
  9. allowFiltering: false
  10. },
  11. {
  12. columnKey: "Stock",
  13. condition: "greaterThan" // Also set the default condition
  14. }
  15. ]
  16. }

Ignite UI Data grid

Ignite UI Data grid

GroupBy

This feature helps in grouping the products. You can easily understand the value of the particular set of products.

Code

  1. name: "GroupBy",
  2. /By default set the groupby value of particular column
  3. columnSettings: [
  4. {
  5. columnKey: "ProductName",
  6. isGroupBy: true
  7. }
  8. ]

Ignite UI Data grid

Just drag and drop the columns to the Groupby section for grouping the data.

Ignite UI Data grid

Finally, the code looks like below

Code

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script src="https://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
  5. <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  6. <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
  7. <!-- Ignite UI Required Combined JavaScript Files -->
  8. <script src="https://cdn-na.infragistics.com/igniteui/2017.2/latest/js/infragistics.core.js"></script>
  9. <script src="https://cdn-na.infragistics.com/igniteui/2017.2/latest/js/infragistics.lob.js"></script>
  10. <!-- Ignite UI Required Combined CSS Files -->
  11. <link href="https://cdn-na.infragistics.com/igniteui/2017.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
  12. <link href="https://cdn-na.infragistics.com/igniteui/2017.2/latest/css/structure/infragistics.css" rel="stylesheet" />
  13. </head>
  14. <body>
  15. <table id="grid"></table>
  16. <script>
  17. $(function() {
  18. var datas;
  19. var results = [];
  20. $.ajax({
  21. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('accessoriesdata')/items?$top=5000",
  22. method: "GET",
  23. headers: {
  24. "Accept": "application/json; odata=verbose"
  25. },
  26. success: function(data) {
  27. datas = data.d.results;
  28. console.log(datas);
  29. for (i = 0; i < datas.length; i++) {
  30. results.push({
  31. "ProductID": datas[i].ProductID,
  32. "ProductName": datas[i].Title,
  33. "Category": datas[i].Category,
  34. "Stock": datas[i].Stock
  35. });
  36. }
  37. console.log(results);
  38. initigGrid(results)
  39. },
  40. error: function(error) {
  41. console.log(JSON.stringify(error));
  42. }
  43. });
  44. });
  45. function initigGrid(value) {
  46. $("#grid").igGrid({
  47. autoGenerateColumns: false,
  48. primaryKey: "ProductID",
  49. caption : "<span> <img src='https://sharepointtechie.sharepoint.com/sites/auto/SiteAssets/sp.png' alt='sharepoint' height='50px'></span>",
  50. width: '100%',
  51. columns: [{
  52. headerText: "Product ID",
  53. key: "ProductID",
  54. dataType: "number",
  55. hidden: true
  56. },
  57. {
  58. headerText: "Product Name",
  59. key: "ProductName",
  60. dataType: "string"
  61. },
  62. {
  63. headerText: "Category",
  64. key: "Category",
  65. dataType: "string"
  66. },
  67. {
  68. headerText: "Stock",
  69. key: "Stock",
  70. dataType: "number"
  71. }
  72. ],
  73. dataSource: value,
  74. features: [{
  75. name: "Paging",
  76. pageSize: 10
  77. },
  78. {
  79. name: "Sorting",
  80. type: "local"
  81. },
  82. {
  83. name: "Filtering",
  84. type: "local",
  85. columnSettings: [{
  86. columnKey: "ProductName",
  87. allowFiltering: false
  88. },
  89. {
  90. columnKey: "Stock",
  91. condition: "greaterThan"
  92. }
  93. ]
  94. },
  95. {
  96. name: "Resizing"
  97. },
  98. {
  99. name: "GroupBy",
  100. columnSettings: [{
  101. columnKey: "ProductName",
  102. isGroupBy: true
  103. }]
  104. },
  105. ]
  106. });
  107. }
  108. </script>
  109. </body>
  110. </html>

Ignite UI Data grid

Get connected to learn more features of the Infragistics data grid in my upcoming articles.

Happy SharePointing!!!