public inbox for yew-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: data table: add table scroll callback
Date: Wed,  7 May 2025 16:37:58 +0200	[thread overview]
Message-ID: <20250507143800.3461963-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250507143800.3461963-1-d.csapak@proxmox.com>

sometimes it's useful to do things on scrolling, e.g. when wanting to
load additional data when at the end of the table.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/widget/data_table/data_table.rs | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/widget/data_table/data_table.rs b/src/widget/data_table/data_table.rs
index f926955..cb0f781 100644
--- a/src/widget/data_table/data_table.rs
+++ b/src/widget/data_table/data_table.rs
@@ -7,7 +7,7 @@ use derivative::Derivative;
 use gloo_timers::callback::Timeout;
 use wasm_bindgen::JsCast;
 
-use yew::html::IntoPropValue;
+use yew::html::{IntoEventCallback, IntoPropValue};
 use yew::prelude::*;
 use yew::virtual_dom::{Key, VComp, VNode};
 
@@ -212,6 +212,10 @@ pub struct DataTable<S: DataStore> {
 
     #[prop_or_default]
     pub multiselect_mode: MultiSelectMode,
+
+    /// Table scroll callback
+    #[prop_or_default]
+    pub on_table_scroll: Option<Callback<Event>>,
 }
 
 impl<S: DataStore> AsClassesMut for DataTable<S> {
@@ -456,6 +460,12 @@ impl<S: DataStore> DataTable<S> {
         self.set_multiselect_mode(multiselect_mode);
         self
     }
+
+    /// Builder style method to set the table scroll callback.
+    pub fn on_table_scroll(mut self, cb: impl IntoEventCallback<Event>) -> Self {
+        self.on_table_scroll = cb.into_event_callback();
+        self
+    }
 }
 
 #[derive(Default)]
@@ -1602,8 +1612,18 @@ impl<S: DataStore + 'static> Component for PwtDataTable<S> {
         let column_widths =
             self.column_widths.iter().sum::<f64>() + self.scrollbar_size.unwrap_or_default();
 
+        let on_scroll = {
+            let on_scroll = props.on_table_scroll.clone();
+            move |event: Event| {
+                if let Some(on_scroll) = &on_scroll {
+                    on_scroll.emit(event);
+                }
+            }
+        };
+
         let viewport = Container::new()
             .node_ref(self.scroll_ref.clone())
+            .onscroll(on_scroll)
             .key(Key::from("table-viewport"))
             .class("pwt-flex-fill")
             .style(
-- 
2.39.5



_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel


  parent reply	other threads:[~2025-05-07 14:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 14:37 [yew-devel] [PATCH yew-comp/yew-widget-toolkit 0/4] fix crash and improve task loading Dominik Csapak
2025-05-07 14:37 ` [yew-devel] [PATCH yew-widget-toolkit 1/2] fix #6382: widget: data table: prevent duplicate yew keys for rows Dominik Csapak
2025-05-08  8:50   ` Dietmar Maurer
2025-05-07 14:37 ` Dominik Csapak [this message]
2025-05-08  9:08   ` [yew-devel] applied: [PATCH yew-widget-toolkit 2/2] widget: data table: add table scroll callback Dietmar Maurer
2025-05-07 14:37 ` [yew-devel] [PATCH yew-comp 1/2] tasks: improve behavior of loading additional tasks Dominik Csapak
2025-05-07 14:38 ` [yew-devel] [PATCH yew-comp 2/2] tasks: don't add entries we already loaded Dominik Csapak
2025-05-08  9:32   ` Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250507143800.3461963-3-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=yew-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal