Documentation
Live Updates
SimpleTable provides powerful tools for creating dynamic, real-time tables with data that updates on the fly. Using the tableRef and updateData API, you can update individual cells with smooth visual feedback through the cellUpdateFlash feature.
Basic Usage
To enable live updates in your table, follow these steps:
- Create a table reference - Create a ref using
useRefand pass it to thetableRefprop - Enable flash animation - Set the
cellUpdateFlashprop totrueto enable visual feedback on cell updates - Update data - Call
tableRef.current.updateData()with the appropriate parameters to update specific cells
Live Update Configuration
The TableRef Interface
The TableRefType provides methods to interact with the table. Currently, it offers the updateData method:
updateData Method Parameters
1// Example: Update multiple cells2const updatePrices = () => {3 // Update first row4 tableRef.current?.updateData({5 accessor: "price",6 rowIndex: 0,7 newValue: 25.998 });910 // Update third row11 tableRef.current?.updateData({12 accessor: "status",13 rowIndex: 2,14 newValue: "updated"15 });16};
Cell Update Flash Animation
When cellUpdateFlash is enabled, cells will momentarily highlight when their value changes, providing a subtle visual cue to users:
1<SimpleTable2 cellUpdateFlash={true} // Enable the flash animation3 defaultHeaders={headers}4 rows={tableData}5 tableRef={tableRef}6/>
Important Notes
- When updating cells, remember to also update your local state to keep it in sync with the table
- The flash effect is subtle by design to avoid distracting users with too much motion
- Updates are best used for small, incremental changes rather than complete table refreshes
Live Updates with Charts
Chart columns work seamlessly with live updates. You can update chart data in real-time while maintaining a fixed array length by adding new values and removing old ones. The demo above shows this in action with Stock Trend (line chart) and Sales Trend (bar chart) columns.
1// Example: Update chart with new data point2const updateStockHistory = (rowIndex: number, newStock: number) => {3 // Get current history4 const currentHistory = data[rowIndex].stockHistory as number[];56 // Add new value and remove oldest (keep array length constant)7 const updatedHistory = [...currentHistory.slice(1), newStock];89 // Update the table10 tableRef.current?.updateData({11 accessor: "stockHistory",12 rowIndex: rowIndex,13 newValue: updatedHistory,14 });15};1617// Update both stock value and chart18tableRef.current?.updateData({19 accessor: "stock",20 rowIndex: 0,21 newValue: 150,22});2324updateStockHistory(0, 150); // Add to chart
💡 Pro Tip
Use custom chartOptions colors (like green for stock and orange for sales) to make charts stand out against theme backgrounds. This is especially important for themes with blue row backgrounds where default blue chart colors would blend in. See the Chart Columns documentation for more details.
Real-world Use Cases
Live updates are particularly valuable in these scenarios:
- Financial dashboards - Display real-time stock price changes and trades
- Inventory management - Show live updates as items are purchased or restocked
- Analytics dashboards - Present data metrics that update as new information arrives
- Sports statistics - Display live game scores and player statistics
- IoT monitoring - Show sensor readings that update in real-time