-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add `shadowRoot` option for grids inside a shadow DOM tree * add shadow DOM example
- Loading branch information
1 parent
3102983
commit 548355e
Showing
4 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | ||
<link rel="shortcut icon" type="image/ico" href="favicon.ico" /> | ||
<title>SlickGrid example 1a: Basic grid inside a shadow DOM</title> | ||
<link rel="stylesheet" href="../dist/styles/css/example-demo.css" type="text/css"/> | ||
</head> | ||
<body> | ||
<table width="100%"> | ||
<tr> | ||
<td valign="top" width="50%"> | ||
<div id="host"></div> | ||
</td> | ||
<td valign="top"> | ||
<div> | ||
<h2> | ||
<a href="/examples/index.html" style="text-decoration: none; font-size: 22px">⌂</a> | ||
Demonstrates: | ||
</h2> | ||
</div> | ||
<ul> | ||
<li>how to load a grid inside a shadow DOM tree</li> | ||
</ul> | ||
<h2>View Source:</h2> | ||
<ul> | ||
<li><A href="https://github.com/6pac/SlickGrid/blob/master/examples/example1a-shadow-dom.html" target="_sourcewindow"> View the source for this example on Github</a></li> | ||
</ul> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/sortablejs/Sortable.min.js"></script> | ||
<script src="sortable-cdn-fallback.js"></script> | ||
|
||
<script src="../dist/browser/slick.core.js"></script> | ||
<script src="../dist/browser/slick.interactions.js"></script> | ||
<script src="../dist/browser/slick.grid.js"></script> | ||
|
||
<script> | ||
var grid; | ||
var columns = [ | ||
{id: "title", name: "Title", field: "title"}, | ||
{id: "duration", name: "Duration", field: "duration"}, | ||
{id: "%", name: "% Complete", field: "percentComplete", width: 90 }, | ||
{id: "start", name: "Start", field: "start"}, | ||
{id: "finish", name: "Finish", field: "finish"}, | ||
{id: "effort-driven", name: "Effort Driven", field: "effortDriven", width: 90 } | ||
]; | ||
|
||
var data = []; | ||
for (var i = 0; i < 500; i++) { | ||
data[i] = { | ||
title: "Task " + i, | ||
duration: "5 days", | ||
percentComplete: Math.round(Math.random() * 100), | ||
start: "01/01/2009", | ||
finish: "01/05/2009", | ||
effortDriven: (i % 5 == 0) | ||
}; | ||
} | ||
|
||
/** | ||
* Build the shadow DOM. In this example, it will | ||
* have just a div for the grid, and a <link> | ||
* for the Alpine style. | ||
* | ||
* Notice that the <link> tag must be placed inside | ||
* the shadow DOM tree, it cannot be placed on the <head> | ||
* tag because the shadow DOM is unaffected by external | ||
* styles | ||
*/ | ||
|
||
var host = document.querySelector("#host"); | ||
var shadow = host.attachShadow({ mode: "open" }); | ||
var gridContainer = document.createElement("div"); | ||
gridContainer.style.width = "600px"; | ||
gridContainer.style.height = "500px"; | ||
gridContainer.classList.add("slick-container"); | ||
shadow.appendChild(gridContainer); | ||
|
||
var linkElement = document.createElement("link"); | ||
linkElement.type = "text/css"; | ||
linkElement.rel = "stylesheet"; | ||
linkElement.href = "../dist/styles/css/slick-alpine-theme.css"; | ||
shadow.appendChild(linkElement); | ||
|
||
/** | ||
* Since the grid is inside a shadow DOM tree, we have | ||
* to pass the root of this tree to the option `shadowRoot` | ||
*/ | ||
|
||
var options = { | ||
enableCellNavigation: true, | ||
enableColumnReorder: false, | ||
shadowRoot: shadow | ||
}; | ||
|
||
/** | ||
* Since the <link> tag was loaded dynamically, it will take | ||
* some time to download the referenced css file. We must | ||
* wait for the style to finish loading, otherwise Slick.Grid | ||
* will break | ||
*/ | ||
|
||
linkElement.addEventListener("load", () => { | ||
grid = new Slick.Grid(gridContainer, data, columns, options); | ||
}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters