You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by hu...@apache.org on 2022/03/27 19:01:37 UTC
[royale-asjs] branch develop updated: Added scrollToIndex in Jewel DataGrid
This is an automated email from the ASF dual-hosted git repository.
hugoferreira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 01c01b0 Added scrollToIndex in Jewel DataGrid
01c01b0 is described below
commit 01c01b07b2fc20d83083c2bdd925009d2a1ef582
Author: Hugo Ferreira <hf...@solidsoft.pt>
AuthorDate: Sun Mar 27 20:01:39 2022 +0100
Added scrollToIndex in Jewel DataGrid
---
.../royale/org/apache/royale/jewel/DataGrid.as | 18 ++++++++++
.../royale/jewel/beads/views/DataGridView.as | 41 +++++++++++++++++++++-
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DataGrid.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DataGrid.as
index 3a5348f..f28eecf 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DataGrid.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DataGrid.as
@@ -28,6 +28,7 @@ package org.apache.royale.jewel
import org.apache.royale.jewel.beads.models.DataGridPresentationModel;
import org.apache.royale.jewel.supportClasses.datagrid.IDataGridPresentationModel;
import org.apache.royale.html.util.getModelByType;
+ import org.apache.royale.jewel.beads.views.IScrollToIndexView;
/**
* The change event is dispatched whenever the datagrid's selection changes.
@@ -230,6 +231,23 @@ package org.apache.royale.jewel
}
/**
+ * Ensures that the data provider item at the given index is visible.
+ *
+ * @param index The index of the item in the data provider.
+ *
+ * @return <code>true</code> if the scroll changed.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Royale 0.9.7
+ */
+ public function scrollToIndex(index:int):Boolean
+ {
+ return (view as IScrollToIndexView).scrollToIndex(index);
+ }
+
+ /**
* load necesary beads. This method can be override in subclasses to
* add other custom beads needed, so all requested beads be loaded before
* signal the "beadsAdded" event.
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DataGridView.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DataGridView.as
index f959c4e..795d18c 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DataGridView.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DataGridView.as
@@ -64,7 +64,7 @@ package org.apache.royale.jewel.beads.views
* @playerversion AIR 2.6
* @productversion Royale 0.9.7
*/
- public class DataGridView extends GroupView implements IBeadView, IDataGridView
+ public class DataGridView extends GroupView implements IBeadView, IDataGridView, IScrollToIndexView
{
/**
* constructor.
@@ -138,7 +138,46 @@ package org.apache.royale.jewel.beads.views
}
}
+ /**
+ * Ensures that the data provider item at the given index is visible.
+ *
+ * If the item is visible, the <code>verticalScrollPosition</code>
+ * property is left unchanged even if the item is not the first visible
+ * item. If the item is not currently visible, the
+ * <code>verticalScrollPosition</code>
+ * property is changed make the item the first visible item, unless there
+ * aren't enough rows to do so because the
+ * <code>verticalScrollPosition</code> value is limited by the
+ * <code>maxVerticalScrollPosition</code> property.
+ *
+ * @param index The index of the item in the data provider.
+ *
+ * @return <code>true</code> if <code>verticalScrollPosition</code> changed.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Royale 0.9.7
+ */
+ public function scrollToIndex(index:int):Boolean
+ {
+ COMPILE::JS {
+ if (index == -1) return false;
+
+ var scrollArea:HTMLElement = listArea.element;
+ var oldScroll:Number = scrollArea.scrollTop;
+
+ var rowHeight:Number = _presentationModel.rowHeight;
+ var totalHeight:Number = sharedModel.dataProvider.length * rowHeight - scrollArea.clientHeight;
+
+ scrollArea.scrollTop = Math.min(index * rowHeight, totalHeight);
+ return oldScroll != scrollArea.scrollTop;
+ }
+ COMPILE::SWF {
+ return false;
+ }
+ }
/**
* @private