diff --git a/README.md b/README.md index 0fa704a..ee58604 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,173 @@ -# Add Blazor Spreadsheet Component in Blazor Server App +# Add a JavaScript Spreadsheet Component in a Blazor Server App -This sample explains about how to add Blazor Spreadsheet component in Blazor server application. +This repository demonstrates how to integrate a JavaScript Spreadsheet component into a Blazor Server application targeting .NET 6. The sample shows how to reference the Spreadsheet’s JavaScript and CSS assets, initialize it using JavaScript interop, and render it on a Razor page. While the example is aligned with the Syncfusion EJ2 JavaScript Spreadsheet loaded via CDN for convenience, the overall approach works with other JavaScript spreadsheet libraries as well. The goal is to help you understand where to place assets, how to structure initialization, and how to keep the component lifecycle clean in a Blazor Server context. + +Note: If you use a commercial component, make sure to review and comply with its licensing terms. + +## What You’ll Build + +A .NET 6 Blazor Server application that: + +- Loads a JavaScript spreadsheet component from a CDN or local assets. +- Initializes the spreadsheet via Blazor’s JavaScript interop. +- Displays a small in-memory dataset with basic formatting (e.g., bold headers, currency formatting). +- Configures common features like toolbar items, editing, sorting, and filtering. + +## Tech Stack + +- **.NET 6 (Blazor Server)**: Core framework for the application. +- **JavaScript Spreadsheet Library**: Example uses Syncfusion EJ2; adaptable to other libraries. +- **JavaScript Interop (`IJSRuntime`)**: Enables communication between Blazor and JavaScript. ## Prerequisites -* Visual Studio 2022 +- **.NET SDK 6.0**: Installed on your system. +- **IDE**: Visual Studio 2022 (v17.0 or newer) or Visual Studio Code with C# extensions. +- **Browser**: A modern browser (Microsoft Edge, Google Chrome, or Firefox). +- **Internet Access**: Required for CDN assets; optional if hosting assets locally. + +## Repository Structure + +- `Pages/Index.razor`: Hosts the spreadsheet container and triggers initialization via JavaScript interop. +- `Pages/_Layout.cshtml`: Includes stylesheet and script references for the spreadsheet library and interop logic. +- `Program.cs`: Configures the Blazor Server hosting setup for .NET 6. + +## Getting Started + +1. Clone the repository using your preferred Git client and navigate to the project folder. +2. Restore dependencies and build the solution: + + ```bash + dotnet restore + dotnet build + ``` + +3. Run the project: + + ```bash + dotnet run + ``` + +4. Open your browser to the URL displayed in the console or IDE output (e.g., `https://localhost:5001`). You should see a spreadsheet populated with sample data. If issues occur, refer to the **Troubleshooting** section. + +## Adding Spreadsheet Assets and Interop JavaScript + +In `Pages/_Layout.cshtml`, include the spreadsheet library’s stylesheet in the `
` tag to ensure styles are available during rendering. Place the spreadsheet script bundle near the end of the ``, after the Blazor Server script (`blazor.server.js`), to ensure proper initialization order. For CDN usage, reference the correct library version and dependencies. If external network access is restricted, download assets and serve them from the `wwwroot` folder, updating paths accordingly. Maintain this inclusion order: + +1. Spreadsheet stylesheet (in ``). +2. Blazor Server script. +3. Spreadsheet library bundle. +4. Custom interop script. + +Example in `Pages/_Layout.cshtml`: + +```html + + + + + +