Frontend School

Interactive Spreadsheet Cell Grid with Live Sum

Machine Coding
medium

Interactive Spreadsheet Cell Grid with Live Sum

Medium
Frontend
React
UI
Spreadsheet
Grid

Overview

Spreadsheets are fundamental tools for data organization and analysis. Building a simplified interactive grid component is a common task in frontend development, touching upon state management, event handling, and dynamic rendering. This problem challenges you to create a core part of a spreadsheet application: an editable cell grid that can dynamically calculate the sum of its numeric contents.

What you need to do / Task

Your goal is to implement a React component that displays a grid of cells with the following functionalities:

  1. Render a Grid: Display a 5x5 grid of cells. Each cell should initially display a value. Some cells may contain numbers, others strings.
  2. Editable Cells: When a user clicks on a cell, it should transition into an editable state, displaying an <input type="text" /> element.
  3. Save Cell Value: After editing, pressing the Enter key or clicking outside the input field (blur event) should save the new value and revert the cell back to its display state.
  4. Live Summation: Below the grid, display the sum of all numeric values currently present in the grid's cells. This sum should update automatically whenever any cell's value is changed to a new numeric value. Non-numeric cell values should be ignored in the sum calculation.

UI/UX expectations

  • The grid should be clearly structured, resembling a table or a set of uniform boxes.
  • When a cell is in edit mode, it should be visually distinct (e.g., a border around the input field, a different background).
  • The sum display should be clearly visible below the grid.
  • Basic styling to make the grid and cells presentable is expected.

Acceptance criteria

  • The application renders a 5x5 grid of cells.
  • Each cell correctly displays its initial value.
  • Clicking a cell enables an input field within it for editing.
  • Editing a cell's value and pressing Enter or blurring the input updates the cell's displayed value.
  • The sum displayed below the grid accurately reflects the total of all numeric cell values.
  • The sum updates automatically and correctly whenever a cell's value is modified to a numeric value.
  • Non-numeric cell values (e.g., "hello") are correctly excluded from the sum calculation.

Constraints

Constraints & assumptions

  • The grid size is fixed at 5 rows by 5 columns. You do not need to support dynamic resizing.
  • Cell values can be either numbers or strings.
  • No need to handle complex formulas (e.g., =A1+B1).
  • No need to implement advanced selection (e.g., drag selection, multi-cell selection).
  • No need for keyboard navigation beyond Enter for saving.
  • You can use React state management (e.g., useState).
  • The environment is a standard React application.

Out of scope

  • Implementing undo/redo functionality.
  • Handling copy/paste operations.
  • Persistence of grid data (e.g., saving to local storage or a backend).
  • Any form of data validation beyond basic numeric parsing for summation.

What interviewers evaluate

  • Component Structure & State Management: How effectively the grid data and cell edit states are managed within React components.
  • Event Handling: Correct implementation of click, blur, and keydown events for cell interaction and saving.
  • Dynamic Rendering: Ability to update the UI efficiently based on state changes, particularly for cell values and the live sum.
  • Code Quality & Readability: Clarity, organization, and maintainability of the code.

Loading editor...