Google 图表 - 设置选择不会滚动到表格可视化中的选定行
Google Chart - setSelection does not scroll to selected row in Table visualisation
我正在使用谷歌图表工具在我的网页上显示一个表格可视化以及谷歌地图。当用户单击地图位置时,回调会自动从表中的位置列表中选择相应的位置。
这工作正常,但表格不会自动滚动表格,因此所选行可见(有很多点,因此只有有限的数量显示在表格右侧的滚动条中。
我看不到任何将视口的当前"位置"设置为表格的方法。有没有办法做到这一点?
谢谢!
下面的代码片段:
arrBuoyLocs = new google.visualization.DataTable();
vTable = new google.visualization.Table(document.getElementById('table_div'));
// do initialisation, etc...
.
.
.
function updateSelectedTableItem(buoyid) {
console.log('Searching for %s', buoyid);
idx = -1;
nRows = arrBuoyLocs.getNumberOfRows();
for(iRow = 0; iRow < nRows; iRow++) {
if(arrBuoyLocs.getValue(iRow, 0) == buoyid) {
console.log('Got match for %s at idx %d', buoyid, iRow);
idx = iRow;
break;
}
}
if(idx >= 0) {
vTable.setSelection([{row: idx, column: null}]);
// This highlights the row but does not show it if the row is
// scrolled off the screen. How do I scroll the Table to show
// the selected row?
}
}
我不知道
如何使用谷歌图表 API 做到这一点,但这里有一个想法可能会有所帮助:
如果您可以找到屏幕高度、表格行高并计算屏幕可以容纳多少表格行,那么您可以计算滚动条需要滚动多少才能显示您选择的表格行。
因此,如果您的屏幕高度可以显示 20 行,并且您选择了第 25 行,则滚动条5 * rowHeight + margin
. 这可能可以在 JavaScript 或 Ajax 文件中完成。
基本上,您已经拥有了执行此操作所需的所有数据,只需要找出如何在javascript中以编程方式滚动滚动条即可。
我找到了这个,它有效。
https://groups.google.com/forum/#!searchin/google-visualization-api/table$20setSelection/google-visualization-api/8_atzTNPmL4/etL7VZWjdVQJ
编辑:从中,这将滚动到"table_div"中表格的选定列。我发现这已经足够了,并进行了一些微调以确保我想要的行清晰可见。
function on_row_select() {
// get the container div for the overflowed table
var container = $('#table_div').find('.google-visualization-table-table:eq(0)').parent();
// get the container div for the fixed header
var header = $('#table_div').find('.google-visualization-table-table:eq(1)').parent();
// get the selected row
var row = $('.google-visualization-table-tr-sel');
// set the scroll position of the overflowed div based on the offset position of the row and the height of the fixed header
$(container).prop('scrollTop', $(row).prop('offsetTop') - $(header).height());
}
像这样的东西。这个答案a)不需要jQuery和b)当选定的行已经在屏幕上时不要触摸滚动条。
scrollOnToSelectPosition=function(element) {
var tableElement=element.querySelectorAll("table.google-visualization-table-table")[0],
selection=tableElement.querySelectorAll("tr.google-visualization-table-tr-sel");
if (selection.length) {
var parentDiv=tableElement.parentElement,
tableHead=tableElement.querySelectorAll("thead")[0],
offset=selection[0].offsetTop-tableHead.clientHeight,
viewHeight=parentDiv.clientHeight-tableHead.clientHeight;
if (offset>parentDiv.scrollTop && offset<parentDiv.scrollTop+viewHeight) {
if (offset+selection[0].clientHeight>parentDiv.scrollTop+viewHeight) {
parentDiv.scrollTop=offset+selection[0].clientHeight-viewHeight;
}
}
else {
parentDiv.scrollTop=offset;
}
}
},
相关文章:
- 如何在谷歌可视化中组合数字和模式格式化程序
- 加载泰坦尼克号可视化数据时出现问题
- 如何使用图表包装函数有条件地格式化谷歌可视化表单元格
- AngularJS&Google可视化-使用状态更改处理程序(Google API)在HTML页面上查看$sco
- Javascript图形可视化工具包,具有高性能(500-1000个节点)
- Google可视化addListener调用函数引用错误
- 如何在web上动态可视化数据集
- 可视化到选择框中
- 从特定系列的谷歌可视化折线图中删除悬停工具提示
- 谷歌图表可视化仪表板数据源问题
- 在可视化中将CSS从悬停更改为单击
- 使用 d3 可视化快速射击的“点击”
- 为 D3 可视化创建平均 Y 线
- Google 图表 - 设置选择不会滚动到表格可视化中的选定行
- 如何使用谷歌可视化API来检索谷歌电子表格单元格值
- 谷歌可视化表格图表 - 更改列名称
- 加载谷歌电子表格以使用传单进行可视化
- 使用amCharts在工具提示上可视化表格
- 谷歌可视化查询&表格-没有返回正确的行简单的电子表格
- 如何使用谷歌可视化查询搜索电子表格-基于多重搜索标准