🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
pass data through rows
  • Loading branch information
levkk committed Sep 6, 2023
commit c1773ba16a0ed22b23eae6e96a3e58aa8ea35633
7 changes: 7 additions & 0 deletions pgml-dashboard/src/components/tables/large/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@ use sailfish::TemplateOnce;
pub struct Row {
columns: Vec<Component>,
action: String,
data: Vec<(String, String)>,
}

impl Row {
pub fn new(columns: &[Component]) -> Row {
Row {
columns: columns.to_vec(),
action: "click->tables-large-table#selectRow".to_string(),
data: vec![],
}
}

pub fn action(mut self, action: &str) -> Self {
self.action.push_str(&format!(" {}", action));
self
}

pub fn data(mut self, name: &str, value: &str) -> Self {
self.data.push((name.to_owned(), value.to_owned()));
self
}
}

component!(Row);
3 changes: 3 additions & 0 deletions pgml-dashboard/src/components/tables/large/row/template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<tr
data-action="<%= action %>"
data-tables-large-table-target="row"
<% for (name, value) in data { %>
data-<%= name %>="<%= value %>"
<% } %>
>
<% for column in columns { %>
<td>
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/static/js/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
selectRow(event) {
alert('Selected a row')
console.log('dataset: ', event.currentTarget.dataset)
}
}
9 changes: 6 additions & 3 deletions pgml-dashboard/templates/content/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@ <h3 class="h3">Playground</h3>
"20:00:43.956373 +00:00:00 UTC".into(),
"Ready".into()
])
.action("click->playground#selectRow"),
.action("click->playground#selectRow")
.data("row-id", "1"),

Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()
])
.action("click->playground#selectRow"),
.action("click->playground#selectRow")
.data("row-id", "2"),

Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()
])
.action("click->playground#selectRow"),
.action("click->playground#selectRow")
.data("row-id", "3"),

])
.selectable()
Expand Down