Download the PHP package mage/grid without Composer
On this page you can find all versions of the php package mage/grid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package grid
Mage Grid Module
A powerful and flexible grid system for Magento 2 that provides an easy way to create and manage data grids in the admin panel.
Features
- Flexible Data Sources: Support for both collection-based and SQL-based data sources
- AJAX Support: Built-in AJAX functionality for smooth data loading
- Customizable Fields: Easy field configuration and management
- Built-in Filtering: Advanced filtering capabilities
- Pagination: Automatic pagination handling
- Frontend & Backend Support: Works in both frontend and backend contexts
- Responsive Design: Mobile-friendly grid layout
- Customizable Templates: Easy to override and customize templates
Why Our Grid is Better Than Magento's Legacy Grid
Our grid implementation offers several advantages over Magento's legacy grid system:
-
Modern Technology Stack:
- Uses GridJS, a modern JavaScript grid library
- Built with Preact for efficient rendering
- Supports modern JavaScript features and async/await
-
Better Performance:
- Lighter weight than Magento's legacy grid
- Faster rendering and data loading
- Reduced server load with client-side processing
-
Enhanced Flexibility:
- Easy to customize columns and cells
- Support for both collection and SQL-based data sources
- Simple integration with Magento's UI components
-
Improved Developer Experience:
- Cleaner code structure
- Better separation of concerns
- Easier to extend and maintain
-
Better User Experience:
- Smoother interactions
- More responsive interface
- Better mobile support
-
Advanced Features:
- Built-in AJAX support
- Advanced filtering capabilities
- Custom cell renderers
- Dynamic data loading
- Integration with Magento:
- Seamless integration with Magento's admin panel
- Support for Magento's UI components
- Compatible with Magento's theming system
Why This Grid is AI-First
Mage Grid is designed from the ground up to be AI-first. This means:
- The codebase is structured for easy understanding and modification by AI coding assistants (like Cursor, GitHub Copilot, or ChatGPT).
- Naming conventions, modularity, and documentation are optimized for AI-driven code generation and extension.
- The grid is built to be easily extensible and customizable with minimal manual intervention, making it ideal for rapid prototyping and iterative development with AI tools.
- Simple strait forward architecture and access to code with examples and documenttion makes it straightforward for LLMs to read, understand, and even improve your components. AI-Ready: Open code for LLMs to read, understand, and improve.
The design of the Mage Grids makes it easy for AI tools to work with your code. Its open code and simple API allow AI models to read, understand, and generate new components.
What Makes It AI-First?
- Consistent, clear naming: Classes, methods, and templates are named for discoverability and semantic search.
- Separation of concerns: Logic, templates, and configuration are cleanly separated, so AI can suggest or generate changes in isolation.
- Extensive inline documentation: Comments and docblocks are written to help both humans and AI understand intent and usage.
- Configurable via XML and DI: Most features (fields, processors, templates) are configured in XML or DI, so AI can suggest changes without deep PHP edits.
- Composable processors: The data processor system is designed for easy extension and chaining, which is ideal for AI-driven code generation.
- Template-driven UI: UI and JS are in templates, so AI can generate or modify UI logic without touching backend code.
How to Extend Mage Grid Using Cursor or AI
You can use AI tools like Cursor to:
- Add new data processors (e.g., for custom formatting, badges, or links)
- Add or modify grid fields and templates
- Inject new JS/HTML for popups, modals, or custom actions
- Refactor or optimize code for performance or maintainability
Example: Adding a Custom Data Processor with Cursor
- Describe your goal in Cursor:
- "Add a processor that renders the 'priority' field as a colored badge."
- Let Cursor search for DataProcessorInterface and StatusProcessor.
- Cursor generates a new PriorityProcessor.php:
- Implements the interface, adds color logic, and registers in di.xml.
- Update your layout XML to map the 'priority' field to the new processor.
Example: Adding a Popup with AI
- Describe your goal:
- "Add a popup that shows full row details when the 'Order Number' cell is clicked."
- AI suggests a new JS function and a template snippet.
- Add the JS to an additional-html.phtml template and configure it in layout XML.
- AI updates the grid template to include the new popup logic.
Practical Steps for AI-Driven Extension
- Use Cursor's semantic search to find relevant classes, templates, or config files.
- Use inline comments and docblocks to guide AI suggestions.
- Use the modular template and processor system to add or override features without deep code changes.
- Test changes iteratively, letting AI suggest fixes or improvements.
Tip:
- The more you describe your intent (in comments, commit messages, or AI prompts), the better the AI can help you extend or refactor the grid.
AI Assistant Integration
The Mage Grid module includes an advanced AI Assistant that helps users interact with the grid using natural language queries. The AI Assistant:
- Natural Language Filtering: Users can type queries in natural language (e.g., "show orders from last week", "find orders with status pending") and the AI will convert them into appropriate filters.
- Terminal-like Interface: When users type "select" or similar SQL-like keywords, the input field transforms into a terminal-like interface with green text on black background and a blinking cursor.
- Smart Suggestions: Provides alternative filter suggestions when the query is ambiguous or when multiple filtering options are available.
- Context-Aware: Takes into account current filters, pagination, and sorting when suggesting new filters.
- Error Handling: Gracefully handles unclear queries and asks for clarification when needed.
- Performance Optimized: Caches frequent queries and optimizes filter combinations for better performance.
Installation
-
Copy the module to your Magento installation:
-
Enable the module:
-
Run setup upgrade:
- Clear cache:
Usage
Basic Grid Setup
-
Create a layout file (e.g.,
view/adminhtml/layout/your_module_grid_index.xml
): - Create a controller (e.g.,
Controller/Adminhtml/YourGrid/Index.php
):
Custom Column Cells with Preact
The module uses GridJS with Preact for rendering custom column cells. Here's how to create custom column cells:
-
Basic Custom Column:
-
Complex Custom Column with Magento Integration:
-
Custom Column with AJAX Data:
-
Custom Column with Magento UI Components:
- Custom Column with Magento Form Elements:
Configuration Options
The grid supports various configuration options:
-
Collection-based Grid:
-
SQL-based Grid:
-
Field Configuration:
-
Pagination:
- Filters:
Customization
-
Override Template: Create your own template at
view/adminhtml/templates/grid/grid-component.phtml
- Custom ViewModel:
Extend
GenericViewModelGrid
to add custom functionality:
Customizing the Grid Component Template
The module uses a template file at view/adminhtml/templates/grid/grid-component.phtml
that you can customize. Here are some examples:
-
Basic Custom Column with Formatter:
-
Custom Column with Actions:
-
Custom Column with Magento UI Components:
-
Custom Column with Dynamic Data Loading:
-
Custom Column with Form Elements:
- Custom Column with Filtering:
Security
The module includes built-in security features:
- ACL (Access Control List) integration
- Role-based access control
- XSS protection
- CSRF protection
Support
For support, please contact:
- Email: [email protected]
- GitHub Issues: Create an issue
License
This module is licensed under the MIT License.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Magento 2 Data GridsJS
GridJS and DataTable integration with Magento 2
Grid.js(https://gridjs.io/) is a Free and open-source JavaScript table plugin. It works with most JavaScript frameworks, including React, Angular, Vue and VanillaJs.
Grid.js uses Preact to render the elements and that means that you can take advantage of Preact's Virtual DOM and render complex cells.
DataTable integration with magento
DataTables (https://datatables.net/) is a Javascript HTML table-enhancing library. It is a highly flexible tool, built upon the foundations of progressive enhancement, that adds all of these advanced features to any HTML table.
At First, GridJS was integrated, but after DataTable was added.
All extensions come as jQuery plugins but can work independently.
I also have AG Grid integration for Magento 2 but it is not part of this open source solution. The Best JavaScript Grid in the World The professional choice for developers building enterprise applications
This and all other magento extensions based on this revolutionary extension: https://github.com/Genaker/reactmagento2 it allows running magento without MAgento broken JS and uses better modern solutions
Installation:
usage in Admin Area:
Examples: After installation, examples will be embedded at the bottom of the admin dashboard
Source code of the grid
More Examples GridJS
In this examples, we load the data from an existing HTML table
Grid.js can also convert an HTML table. Simply select the table with jQuery and call Grid:
$("table#myTable").Grid();
You can pass all Grid.js configs to the Grid function. See Grid.js Config for more details.
HTML in cells
Then you can use that in formatter function or directly in data array:
Import server-side data
You can use the server property to load data from a remote server and populate the table:
Server Side Pagination
Add server property to the pagination config to enable server-side pagination. Also, make sure the total property is correctly defined in the main server config block
DataTable example
Loading data
Ajax data is loaded by DataTables simply by using the ajax option to set the URL for where the Ajax request should be made. For example, the following shows a minimal configuration with Ajax sourced data:
JSON data source
When considering Ajax loaded data for DataTables we almost always are referring to a JSON payload - i.e. the data that is returned from the server is in a JSON data structure. This is because the JSON is derived from Javascript and it therefore naturally plays well with Javascript libraries such as DataTables.
Non-jQuery options
If you are initialising DataTables through the new DataTable() option available in DataTables 1.11, you can pass configuration options in using the second parameter of the constructor:
Data rendering
Data within DataTables can be easily rendered to add graphics or colour to your tables, as demonstrated in the example on this page. These examples make use of columns.render to customise the cells in three ways:
Data Processors System
Mage Grid uses a flexible and extensible data processor system to transform and format grid cell values before rendering. This allows you to easily customize how each field is displayed, including adding HTML, formatting dates, prices, statuses, and more.
Dual Processor Configuration
The module supports two ways to configure data processors:
-
Layout XML Configuration (
grid_grid_index.xml
): - DI Configuration (
di.xml
):
Processor Resolution Order
- Layout XML processors take precedence over DI configuration
- If no processor is found in either location, the default processor is used
- Processors can be chained using the
ChainProcessor
Example: Combined Configuration
Processor Types
-
Default Processors:
DefaultProcessor
: Basic HTML escapingStatusProcessor
: Status badge renderingPriceProcessor
: Price formattingDateProcessor
: Date/time formattingObfuscateProcessor
: Data obfuscation
- Custom Processors:
- Implement
Mage\Grid\Api\DataProcessorInterface
- Register in either layout XML or DI configuration
- Can be grid-specific or global
- Implement
Example: Custom Processor
Chain Processor
The ChainProcessor
allows you to combine multiple processors:
Best Practices
- Use layout XML processors for grid-specific customizations
- Use DI configuration for global processors
- Keep processors focused on a single responsibility
- Use the chain processor for complex transformations
- Document processor behavior and dependencies
Additional HTML/JS Templates (Popups, Custom Scripts, etc.)
Mage Grid allows you to inject additional HTML or JavaScript into your grid page using configurable template files. This is useful for adding custom popups, event handlers, or any extra markup/scripts you need for your grid.
How to Use
-
Create your additional template(s):
- Place your custom HTML/JS in
.phtml
files, e.g.:view/adminhtml/templates/grid/additional-html.phtml
view/adminhtml/templates/grid/another-additional-html.phtml
- Place your custom HTML/JS in
-
Configure in layout XML:
-
You can specify one or more additional templates using the
additional_html_templates
argument: - The block will render each template in order. If a template is missing, an error message will be shown for that template.
-
- Access in your main grid template:
- In your main grid template (e.g.
grid-component.phtml
), output the additional HTML:
- In your main grid template (e.g.
Example: Popup Event Handler Integration
If you want to add a popup that shows row details when a status badge is clicked, your additional-html.phtml
might look like:
Important:
- If your grid data is updated dynamically (e.g. via AJAX or Grid.js), you must re-attach event handlers after each update. The above example does this using Grid.js events.
- You can include as many additional templates as you need, and each can contain its own scripts or markup.
Error Handling
- If a specified template does not exist, a user-friendly error message will be shown in the grid output.
Filter Types
The Mage Grid module supports several types of filters that can be configured via layout XML:
Available Filter Types
- Text Input Filter
- Default filter type
- Supports partial matching
- Auto-applies on input change
- Supports Enter key for immediate filtering
- Select Filter
- Single-value selection
- Dropdown interface
- Supports custom source models
- "Any" option included by default
- Multiselect Filter
- Multiple value selection
- Searchable dropdown
- Supports Ctrl/Cmd for multiple selections
- "Any" option for clearing selection
- Built-in search functionality
- Maintains selected state in URL
Filter Features
-
Caching:
- Filter values are cached for better performance
- Cache is applied for results > 100 items
- 24-hour cache lifetime for filter options
- Cache is tagged for easy management
-
URL Integration:
- Filter states are maintained in URL parameters
- Supports browser back/forward navigation
- Bookmarkable filtered states
- Clear all filters functionality
- UI/UX Features:
- Responsive design
- Mobile-friendly dropdowns
- Clear visual feedback
- Consistent styling with Magento admin
- Tooltip hints for usage
Example Configuration
Full example of filter configuration in layout XML:
Custom Source Model
Example of a custom source model for filters:
JavaScript Events
The grid filters emit several events that you can listen to:
Replacing GridJS with Alternative Grid Systems
The Mage Grid module is designed to be flexible and allows you to replace GridJS with any other grid system. Here's how to implement alternative grid solutions:
1. DataTables Integration
To use DataTables instead of GridJS:
-
Create a new template (
view/adminhtml/templates/grid/datatable-component.phtml
): - Update your layout XML to use the new template:
2. Simple HTML Table
For a basic HTML table without JavaScript:
- Create a new template (
view/adminhtml/templates/grid/simple-table.phtml
):
3. Custom Grid System
To implement your own grid system:
- Create a new template with your preferred grid library
-
Use the block's methods to get data and configuration:
getFieldsNames()
: Get field labelsgetGridJsonData()
: Get grid data as JSONgetFieldsConfig()
: Get field configurationsgetProcessedFields()
: Get processed field datagetFiltersHtml()
: Get rendered filters
- Implement your own JavaScript to handle:
- Data loading
- Pagination
- Sorting
- Filtering
Key Components to Override
When replacing GridJS, you mainly need to focus on:
- Template File: Create your own
grid-component.phtml
- JavaScript: Implement your grid initialization
- CSS: Add your grid styling
- Data Processing: Use the existing processor system
The rest of the module (data loading, filtering, processing) remains unchanged.
Example: Using AG Grid
Best Practices
- Keep Data Processing: Use the existing processor system for consistent data formatting
- Maintain Filter Integration: Keep the filter system for consistent filtering
- Preserve Field Configuration: Use the existing field configuration system
- Handle Server-Side Operations: Implement proper server-side pagination and filtering
- Maintain Responsiveness: Ensure your grid works well on all devices
Performance Monitoring & Optimization
The module includes built-in performance metrics to help you monitor and optimize your grid's performance:
Performance Metrics Panel
The grid displays real-time performance metrics including:
- Server SQL Query time
- Server Count time
- AJAX Response time
- Total processing time
These metrics are displayed in the performance panel below the grid and are color-coded:
- Green: Normal performance
- Red: Performance issues detected (>1 second)
Performance Optimization
If you notice performance issues (red indicators), here are some steps to optimize:
-
Query Optimization
- Review your SQL queries using the Magento profiler
- Add appropriate indexes to frequently filtered columns
- Consider implementing query caching
-
Data Loading
- Implement server-side pagination
- Use lazy loading for large datasets
- Consider implementing data caching
- Grid Configuration
- Reduce the number of columns if possible
- Use efficient column formatters
- Implement proper filtering strategies
AI-Powered Optimization
For advanced optimization, you can ask our AI assistant:
The AI will:
- Analyze your current configuration
- Review performance metrics
- Suggest specific optimizations
- Provide code examples for implementation
AI will provide specific recommendations based on your metrics
Remember: Regular performance monitoring and optimization is key to maintaining a responsive and efficient grid system.
API Endpoints
The module provides REST API endpoints for accessing grid data programmatically:
Available Endpoints
-
Get Grid Data
Parameters:
gridId
: Identifier of the gridfilters
: Array of filter criteria (optional)page
: Page number (default: 1)pageSize
: Items per page (default: 20)
Response:
-
Get Grid Configuration
Returns the grid's configuration including:
- Column definitions
- Default settings
- Available filters
-
Get Grid Fields
Returns the list of available fields and their configurations.
-
Get Grid Filters
Returns the available filter options for the grid.
Authentication
All API endpoints require authentication using Magento's standard authentication methods:
- OAuth 2.0
- Integration tokens
- Admin tokens
Example Usage
Performance Monitoring
The API response includes performance metrics to help monitor and optimize grid performance:
execution_time
: Total time taken to process the requestsql_time
: Time taken for SQL queriescount_time
: Time taken for count operations
Error Handling
The API uses standard HTTP status codes and returns detailed error messages:
Rate Limiting
To protect the server, API requests are rate-limited:
- 100 requests per minute per IP
- 1000 requests per hour per user
Best Practices
-
Caching
- Cache responses when possible
- Use ETags for conditional requests
- Implement client-side caching
-
Pagination
- Always use pagination for large datasets
- Keep page size reasonable (20-50 items)
- Use cursor-based pagination for large datasets
-
Filtering
- Use specific filters to reduce data size
- Combine multiple filters when needed
- Cache common filter combinations
- Error Handling
- Implement proper error handling
- Use exponential backoff for retries
- Log errors for monitoring