Mentions
Add @mentions functionality to spreadsheet cells
The mentions feature allows users to reference people, tags, or entities within cells using the @ symbol, similar to social media platforms. This is useful for collaborative spreadsheets, task management, and commenting systems.
Overview
Mentions enable:
User tagging: Reference team members in cells
Entity references: Link to external resources or data
Autocomplete: Dropdown suggestions as users type
Custom rendering: Display mentions with custom styling
Data binding: Connect mentions to your application's data model
Basic Usage
import { SpreadsheetProvider, CanvasGrid } from "@rowsncolumns/spreadsheet";
import { useCallback } from "react";
function SpreadsheetWithMentions() {
const getMentions = useCallback(async (query?: string) => {
// Fetch mentions from your API or database
return [
{ label: "John Doe", value: "user-123" },
{ label: "Jane Smith", value: "user-456" },
{ label: "Marketing Team", value: "team-789" },
];
}, []);
return (
<SpreadsheetProvider>
<CanvasGrid
sheetId={1}
getMentions={getMentions}
// ... other props
/>
</SpreadsheetProvider>
);
}getMentions Function
The getMentions callback is called when users type @ in a cell. It should return a Promise that resolves to an array of mention objects.
Function Signature
Parameters
query (optional): The search text entered by the user after
@
Example with Search
Custom Dropdown Rendering
Customize how mentions appear in the autocomplete dropdown using MentionDropdownItemComponent:
MentionDropdownItemComponent Props
Async Data Loading
Fetch mentions from an API:
Complete Example
Accessing Mention Data
When a mention is selected, it's stored in the cell data. You can access it through the cell's data structure:
Use Cases
Team Collaboration
Project Management
Comments and Notes
Styling
Mentions in cells can be styled using custom text format runs. The spreadsheet automatically formats mentioned text when rendered.
Performance Optimization
Debounced Search
Caching
Best Practices
Limit Results: Return a maximum of 10-20 mentions to keep the dropdown manageable
Fast Response: Keep the
getMentionsfunction fast (< 300ms) for good UXError Handling: Handle API failures gracefully and return an empty array
Unique Values: Ensure each mention has a unique
valuepropertyClear Labels: Use descriptive labels that help users identify the right mention
Type Safety: Use TypeScript to define your mention structure
Troubleshooting
Mentions Not Appearing
Verify
getMentionsreturns an array of objects withlabelandvaluepropertiesCheck that the function returns a Promise
Ensure there are no JavaScript errors in the console
Search Not Working
Confirm the
queryparameter is being used in your filter logicTest the search function independently
Check for case sensitivity issues
Slow Performance
Implement debouncing for API calls
Add caching for frequently accessed results
Limit the number of returned results
Use pagination for large datasets
Last updated
Was this helpful?