-
Hi Team. I was trying sorting feature in a wave table. In my app, data passes as a dataframe. I can see when the row count increases the sorting functionality doesn't work as expected. Each time when I click on a column heading for a sort, it increases the table row count by repeating the data in the table. To recreate the behaviour I used below code in Wave tour app (Instance 0.25.2). Small demo is also attached here with. For testing just vary import pandas as pd
import random
from typing import List
from pandas.core.frame import DataFrame
from h2o_wave import main, app, Q, ui, TableRow, Component
# Create columns for our issue table.
columns = [
ui.table_column(name='name', label='Name', sortable=True, ),
ui.table_column(name='subject', label='Subject', sortable=True, ),
ui.table_column(name='mark', label='Mark', data_type="number", sortable=True, ),
]
number_of_rows = 5
def get_table_rows(
df: DataFrame
) -> List[TableRow]:
"""Get table rows table"""
return [
ui.table_row(
name=str(row['name']),
cells=[
str(row['name']),
str(row['subject']),
str(row['marks']),
]
) for index, row in df.iterrows()
]
@app('/demo')
async def serve(q: Q):
# Sample data generation
names = ["John", "Alice", "Bob", "Emma", "Michael", "Olivia", "Sophia", "William", "James", "Ethan"]
subjects = ["Math", "English", "Science", "History", "Computer Science", "Art", "Music", "Physics", "Chemistry", "Biology"]
data = {
"name": [random.choice(names) for _ in range(number_of_rows)],
"subject": [random.choice(subjects) for _ in range(number_of_rows)],
"marks": [random.randint(50, 100) for _ in range(number_of_rows)]
}
# Creating the data frame
df = pd.DataFrame(data)
q.page['form'] = ui.form_card(box='1 1 -1 7', items=[
ui.table(
name='issues',
columns=columns,
rows=get_table_rows(df),
)
])
await q.page.save() Screen.Recording.2023-08-07.at.09.27.20.movcc: @mturoci |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Table rows must be unique so instead of using return [
ui.table_row(
name=str(index),
cells=[
str(row['name']),
str(row['subject']),
str(row['marks']),
]
) for index, row in df.iterrows()
] |
Beta Was this translation helpful? Give feedback.
Table rows must be unique so instead of using
name
col as key, go for index for example: