Forum Discussion
Auto Scrolling Table
Anonymous
No.
I found workarounds instead.
I'll be happy to find a solution for my initial request.
Cheers!
Hi guys,
Take an example below. It should help.
<html>
<head>
<style>
div.items {
height: 100px;
width: 200px;
border: 1px solid black;
overflow-y: scroll;
}
div.items div {
height: 20px;
}
</style>
<script>
function addNewItem() {
const itemsElement = document.getElementById("items");
const newItem = document.createElement("div");
newItem.innerText = "New item";
itemsElement.appendChild(newItem);
itemsElement.scrollTop = (itemsElement.children.length) * 20 - 100;
}
function autoScrollDown() {
const itemsElement = document.getElementById("items");
itemsElement.scrollTop = 0;
stopPosition = (itemsElement.children.length) * 20 - 100;
const timerId = setInterval(function () {
if (itemsElement.scrollTop >= stopPosition) {
clearInterval(timerId);
}
itemsElement.scrollTop += 1;
}, 100);
}
</script>
</head>
<body>
<h1>Scroll positioning example</h1>
<button onclick="addNewItem()">Add new item</button>
<button onclick="autoScrollDown()">Auto Scroll Down</button>
<br /><br />
<div id="items" class="items">
<div>Old item 1</div>
<div>Old item 2</div>
<div>Old item 3</div>
<div>Old item 4</div>
<div>Old item 5</div>
<div>Old item 6</div>
<div>Old item 7</div>
<div>Old item 8</div>
</div>
</body>
</html>
Kind Regards,
Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
[email protected]
- Anonymous7 years agoNot applicable
Hi v-evelk
Thanks for the info.
Did you try it inside a Power BI report?
While it works fine as a simple HTML page, it is not working for me inside a power BI report page.+ I am not sure how to trigger the function to automatically start.
I have basic knowledge and experience in JS, sorry if I am missing any fundamental stuff here.
Cheers!
- v-evelk7 years agoMicrosoft Employee
Hi,
Yes, it works perfectly inside a visual.
I checked this with creation of an initial visual by this instruction but I used beta version of tools that supports WebPack.
npm i -g powerbi-visuals-tools@beta
Then I inserted the code that I provided above with little adaption:
"use strict"; import "@babel/polyfill"; import "./../style/visual.less"; import powerbi from "powerbi-visuals-api"; import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions; import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions; import IVisual = powerbi.extensibility.visual.IVisual; import EnumerateVisualObjectInstancesOptions = powerbi.EnumerateVisualObjectInstancesOptions; import VisualObjectInstance = powerbi.VisualObjectInstance; import DataView = powerbi.DataView; import VisualObjectInstanceEnumerationObject = powerbi.VisualObjectInstanceEnumerationObject; import { VisualSettings } from "./settings"; function addNewItem() { const itemsElement = document.getElementById("items"); const newItem = document.createElement("div"); newItem.innerText = "New item"; itemsElement.appendChild(newItem); itemsElement.scrollTop = (itemsElement.children.length) * 20 - 100; } function autoScrollDown() { const itemsElement = document.getElementById("items"); itemsElement.scrollTop = 0; const stopPosition = (itemsElement.children.length) * 20 - 100; const timerId = setInterval(function () { if (itemsElement.scrollTop >= stopPosition) { clearInterval(timerId); } itemsElement.scrollTop += 1; }, 100); } export class Visual implements IVisual { private target: HTMLElement; private settings: VisualSettings constructor(options: VisualConstructorOptions) { this.target = options.element; if (typeof document !== "undefined") { const container: HTMLElement = document.createElement("div"); container.innerHTML = ` <h1>Scroll positioning example</h1> <button id="addNewItemButton">Add new item</button> <button id="AutoScrollDownButton">Auto Scroll Down</button> <br /><br /> <div id="items" class="items"> <div>Old item 1</div> <div>Old item 2</div> <div>Old item 3</div> <div>Old item 4</div> <div>Old item 5</div> <div>Old item 6</div> <div>Old item 7</div> <div>Old item 8</div> </div> `; this.target.appendChild(container); const addBtn = document.getElementById("addNewItemButton"); addBtn.addEventListener("click", addNewItem); const autoscrollBtn = document.getElementById("AutoScrollDownButton"); autoscrollBtn.addEventListener("click", autoScrollDown); } } public update(options: VisualUpdateOptions) { } private static parseSettings(dataView: DataView): VisualSettings { return VisualSettings.parse(dataView) as VisualSettings; } /** * This function gets called for each of the objects defined in the capabilities files and allows you to select which of the * objects and properties you want to expose to the users in the property pane. * */ public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject { return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options); } }Styles I moved into .less file.
And that's it!
Please pay more attention in question of learning not only fundamental frontend things but modern things too becuse frontend is developing rapidly and without this knowledge it will be quite troubleshooting to develop Power BI visuals.
Kind Regards,
Evgenii Elkin,
Software Engineer
Microsoft Power BI Custom Visuals
[email protected]