### Example: Configure Inline Edit Text Inputs Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md This example demonstrates how to chain multiple `addText` calls to configure text inputs for inline editing, specifying keys and labels. ```php $inlineEdit = $grid->addInlineEdit('id') ->addText('name', 'Name') ->addText('email', 'Email'); ``` -------------------------------- ### Default Datagrid Configuration Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md A complete example of setting up a Datagrid component in a Presenter factory method. This includes data sources, columns, filters, sorting, pagination, state management, actions, and localization. ```php // In Presenter factory method protected function createComponentGrid(): Datagrid { $grid = new Datagrid(); // Data $grid->setDataSource(new NetteDatabaseTableDataSource($this->db->table('users'))); $grid->setPrimaryKey('id'); // Columns $grid->addColumnText('id', 'ID') ->setSortable(); $grid->addColumnText('name', 'Name') ->setSortable() ->setFilterText(); $grid->addColumnText('email', 'Email') ->setFilterText(); $grid->addColumnLink('name', 'name', 'Detail', 'User:detail', ['id' => 'id']); // Filters $grid->addFilterText('search', 'Search', 'name'); $grid->addFilterSelect('status', 'Status', ['active' => 'Active', 'inactive' => 'Inactive']); // Sorting $grid->setSortable(true); $grid->setDefaultSort(['created_at' => 'DESC']); // Pagination $grid->setPagination(true); $grid->setDefaultPerPage(20); $grid->setItemsPerPageList([10, 20, 50, 100, 'all']); // State $grid->setRememberState(true); $grid->setAutoSubmit(true); // Actions $grid->addAction('detail', 'View', 'User:detail') ->setIcon('eye'); $grid->addActionCallback('delete', 'Delete', function ($id) { $this->db->query('DELETE FROM users WHERE id = ?', $id); }) ->setIcon('trash') ->setConfirmation(new StringConfirmation('Really delete?')); // Multi-select $grid->addMultiAction('delete', 'Delete Selected') ->setCallback(function ($ids) { foreach ($ids as $id) { $this->db->query('DELETE FROM users WHERE id = ?', $id); } }); // Localization $grid->setTranslator(new SimpleTranslator()); return $grid; } ``` -------------------------------- ### Install Datagrid with Composer Source: https://github.com/contributte/datagrid/blob/master/README.md Use Composer to install the latest version of the datagrid package. ```bash composer require ublaboo/datagrid ``` -------------------------------- ### Example: Configure Inline Add Text Inputs Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md This example shows how to configure multiple text inputs for inline row addition, including setting default empty values for each. ```php $inlineAdd = $grid->addInlineAdd() ->addText('name', 'Name', '') ->addText('email', 'Email', ''); ``` -------------------------------- ### Example: Define Inline Add Callback Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md This example demonstrates how to set a callback for the inline add operation, which inserts new user data into the database using the provided form values. ```php $inlineAdd->setCallback(function ($values) { db()->insert('users', $values); }); ``` -------------------------------- ### DibiFluentDataSource Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Instantiate DibiFluentDataSource with a Dibi Fluent query builder instance. Ensure Dibi is configured with a connection. ```php $dibi = Dibi::getConnection(); $query = $dibi->select('*')->from('users')->where('status = ?', 'active'); $dataSource = new DibiFluentDataSource($query); $grid->setDataSource($dataSource); ``` -------------------------------- ### ElasticsearchDataSource Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Initialize ElasticsearchDataSource with an Elasticsearch client instance and the index name. Requires the Elasticsearch client to be built. ```php $client = ClientBuilder::create()->build(); $dataSource = new ElasticsearchDataSource($client, 'users'); $grid->setDataSource($dataSource); ``` -------------------------------- ### Set Filter Value Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Demonstrates how to set a filter's value using the `setValue` method. ```php $filter->setValue('active'); ``` -------------------------------- ### Setup Pagination & State Source: https://github.com/contributte/datagrid/blob/master/_autodocs/README.md Enable pagination with a default number of items per page and configure state persistence in the session. ```php $grid->setPagination(true)->setDefaultPerPage(20); $grid->setRememberState(true); // Persists in session ``` -------------------------------- ### DoctrineCollectionDataSource Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Initialize DoctrineCollectionDataSource with a Doctrine Collection. This data source handles in-memory filtering. ```php $user = $em->find('App\Entity\User', 1); $dataSource = new DoctrineCollectionDataSource($user->getOrders()); $grid->setDataSource($dataSource); ``` -------------------------------- ### Get Available Items Per Page Options Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Use `getItemsPerPageList()` to get an array of all available items-per-page options configured for the datagrid. ```php public function getItemsPerPageList(): array ``` -------------------------------- ### Get Inline Add Instance Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieve the configured inline add instance using `getInlineAdd`. Returns null if not set up. ```php $grid->getInlineAdd(); ``` -------------------------------- ### Require Latest 6.x Version for Preparation Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md Before upgrading to 7.0.x, ensure your 6.x installation is up to date by requiring the latest 6.10 version. ```bash composer require contributte/datagrid:^6.10 ``` -------------------------------- ### NetteDatabaseDataSource Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Instantiate NetteDatabaseDataSource with a Nette Database Result object and set it as the grid's data source. ```php $db = new Nette\Database\Connection(...); $result = $db->query('SELECT * FROM users WHERE status = ?', 'active'); $dataSource = new NetteDatabaseDataSource($result); $grid->setDataSource($dataSource); ``` -------------------------------- ### NextrasDataSource Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Create a NextrasDataSource using a Nextras ORM QueryBuilder instance. This is suitable for integrating with Nextras ORM repositories. ```php $repository = $orm->getRepository(User::class); $qb = $repository->findAll(); $dataSource = new NextrasDataSource($qb); $grid->setDataSource($dataSource); ``` -------------------------------- ### Configure Submit Button Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Example demonstrating how to set both the CSS class and text for the filter submit button using method chaining. ```php $grid->getFilterSubmitButton() ->setClass('btn btn-primary') ->setText('Filter'); ``` -------------------------------- ### Get Export Columns Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Retrieve the list of column keys that are currently configured for export. ```php public function getColumns(): array ``` -------------------------------- ### Configure Pluggable State Storage in v7.1.x Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md Configure the pluggable state storage system in v7.1.x to allow custom storage backends. Examples include using `SessionStateStorage`, `NoopStateStorage`, or a custom implementation like `RedisStateStorage`. ```php use Contributte\Datagrid\Storage\IStateStorage; use Contributte\Datagrid\Storage\SessionStateStorage; use Contributte\Datagrid\Storage\NoopStateStorage; // Default: Session-based storage (same as before) $grid->setStateStorage(new SessionStateStorage()); // Alternative: No persistence $grid->setStateStorage(new NoopStateStorage()); // Custom implementation class RedisStateStorage implements IStateStorage { public function saveState(string $key, mixed $value): void { // Your Redis implementation } public function loadState(string $key, mixed $defaultValue = null): mixed { // Your Redis implementation } public function deleteState(string $key): void { // Your Redis implementation } } $grid->setStateStorage(new RedisStateStorage()); ``` -------------------------------- ### Get Datagrid Data Source Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the currently configured data source for the datagrid. ```php $grid->getDataSource(); ``` -------------------------------- ### DoctrineDataSource Example Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Create a DoctrineDataSource using a Doctrine QueryBuilder instance. This supports automatic filtering, sorting, joins, and pagination. ```php $em = $container->getService('doctrine.em'); $qb = $em->createQueryBuilder() ->select('u') ->from('App\Entity\User', 'u'); $dataSource = new DoctrineDataSource($qb); $grid->setDataSource($dataSource); ``` -------------------------------- ### Configure Column Display Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Control column visibility, order, and export order. This example enables columns to be hidden, sets a specific display order for columns, and defines the order for exported data. ```php $grid->setColumnsHideable(true) ->setColumnsOrder(['id', 'name', 'email', 'actions']) ->setColumnsExportOrder(['name', 'email', 'created_at']); ``` -------------------------------- ### Set Export Columns Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Specify which columns to include in the export. This is useful for controlling the data that gets exported. ```php public function setColumns(array $columns): self ``` ```php $export->setColumns(['id', 'name', 'email']); ``` -------------------------------- ### Update Translation Keys Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md When migrating, verify that translation keys used for DataGrid messages have been updated to match the new library's keys. This example shows how to set up a translator with updated keys. ```php // Verify translation keys are updated $translator = new Nette\Localization\Translator([ 'contributte_datagrid.no_items' => 'No items found' ]); ``` -------------------------------- ### Change Datagrid Filter Form Method Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Set the Datagrid::$formMethod static property to 'get' to use the GET HTTP method for the filter form, which will display filters in the URL. ```php // Use GET method for filters (shows in URL) Datagrid::$formMethod = 'get'; ``` -------------------------------- ### Initialize Basic Datagrid Source: https://github.com/contributte/datagrid/blob/master/_autodocs/README.md Instantiate a Datagrid, set its data source, add a text column with sorting, and define an action. ```php $grid = new Datagrid(); $grid->setDataSource(new ArrayDataSource($data)); $grid->addColumnText('name', 'Name')->setSortable(); $grid->addAction('detail', 'View', 'Page:detail'); return $grid; ``` -------------------------------- ### Configure Filter Behavior Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Control filter submission behavior, set default filter values, and manage the rendering of filters. This example enables auto-submit, sets a default filter for 'status', and configures outer filter rendering with a specific column count. ```php $grid->setAutoSubmit(true) ->setDefaultFilter(['status' => 'active']) ->setOuterFilterRendering(true) ->setOuterFilterColumnsCount(4); ``` -------------------------------- ### Get Inline Edit Instance Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieve the configured inline edit instance using `getInlineEdit`. Returns null if not set up. ```php $grid->getInlineEdit(); ``` -------------------------------- ### Get Column Summaries Instance Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the current ColumnsSummary instance if column summaries are enabled. Returns null if no summary instance is available. ```php $grid->getColumnsSummary(); ``` -------------------------------- ### Get Filter Name Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Retrieves the display label for this filter. ```php public function getName(): string ``` -------------------------------- ### Get Filter Key Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Retrieves the unique identifier for this filter. ```php public function getKey(): string ``` -------------------------------- ### Initialize NetteDatabaseTableDataSource Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Use this to set up a data grid with data from Nette Database. It requires a Nette Database Selection object. ```php $db = new Nette\Database\Connection(...); $users = $db->table('users'); $dataSource = new NetteDatabaseTableDataSource($users); $grid->setDataSource($dataSource); ``` -------------------------------- ### Get Filter Value Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Retrieves the current value set for the filter. ```php public function getValue(): mixed ``` -------------------------------- ### getPaginator Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Get the paginator component instance. Returns null if pagination is disabled. ```APIDOC ## getPaginator ### Description Get the paginator component. ### Method ```php public function getPaginator(): ?DatagridPaginator ``` ### Response #### Success Response (?DatagridPaginator) - **DatagridPaginator|null** - The paginator or null if pagination disabled ``` -------------------------------- ### Initialize ArrayDataSource Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Use this to set up a data grid with data from a PHP array. The array can contain items as arrays or objects. ```php $data = [ ['id' => 1, 'name' => 'John', 'status' => 'active'], ['id' => 2, 'name' => 'Jane', 'status' => 'inactive'], ]; $dataSource = new ArrayDataSource($data); $grid->setDataSource($dataSource); ``` -------------------------------- ### Get Rows from CsvDataModel Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Fetch all the data rows stored within the `CsvDataModel`. ```php public function getRows(): array ``` -------------------------------- ### getParentComponent Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Gets the parent component of the datagrid, which is typically the Presenter in a Nette Framework application. ```APIDOC ## getParentComponent ### Description Get the parent component (usually Presenter). ### Method ```php public function getParentComponent(): Component ``` ### Returns `Component` - The parent component ``` -------------------------------- ### Get Header from CsvDataModel Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Retrieve the header row, which consists of column names, from the `CsvDataModel`. ```php public function getHeader(): array ``` -------------------------------- ### Instantiate and Use SimpleTranslator Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/storage-utilities.md Demonstrates how to instantiate SimpleTranslator with initial translations and set it on a grid object. This is useful for localizing grid column headers or other text elements. ```php $translator = new SimpleTranslator([ 'Name' => 'Jméno', 'Email' => 'E-mail', ]); $grid->setTranslator($translator); ``` -------------------------------- ### Configure Inline Add Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Set up inline adding for grid items, defining text fields and a callback for data insertion. ```php $inlineAdd = $grid->addInlineAdd(); $inlineAdd->addText('name', 'Name', '') ->addText('email', 'Email', '') ->setCallback(function ($values) { db()->insert('users', $values); }); ``` -------------------------------- ### Get Primary Key Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the name of the primary key column currently set for the datagrid. ```php public function getPrimaryKey(): string ``` -------------------------------- ### Catch DatagridColumnException Source: https://github.com/contributte/datagrid/blob/master/_autodocs/errors.md Shows how to catch a DatagridColumnException, which is thrown for general column-related configuration errors. This is important for debugging issues with column setup, type mismatches, or property access. ```php try { $grid->render(); } catch (DatagridColumnException $e) { echo "Column configuration error: " . $e->getMessage(); } ``` -------------------------------- ### Get Datagrid Template File Path Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the path of the currently set template file for the datagrid. This is useful for debugging or dynamic template loading. ```php public function getTemplateFile(): string ``` -------------------------------- ### Get Current State Storage Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the currently active state storage implementation for the Datagrid. ```php public function getStateStorage(): IStateStorage ``` -------------------------------- ### Configure Tree View Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Set up the DataGrid to display data in a tree structure, specifying methods for retrieving children and checking for their existence. ```php $grid->setTreeView( 'getChildren', // Method/property to get children 'hasChildren', // Method/property to check for children true, // Use callback 'category' // Category/parent column ); ``` -------------------------------- ### Get All Columns Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieve all columns currently configured in the datagrid as an associative array, keyed by their identifiers. ```php public function getColumns(): array ``` ```php foreach ($grid->getColumns() as $key => $column) { echo $column->getName(); } ``` ``` -------------------------------- ### Configure Items Per Page Options Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Set the available options for items per page using `setItemsPerPageList()`. The `includeAll` parameter, defaulting to `true`, determines if an 'all' option is added. ```php public function setItemsPerPageList(array $itemsPerPageList, bool $includeAll = true): self ``` ```php $grid->setItemsPerPageList([10, 20, 50, 'all']); ``` -------------------------------- ### Get Filter Type Identifier Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Use getType to retrieve the identifier for the filter's type. ```php public function getType(): ?string ``` -------------------------------- ### Create and Configure GroupButtonAction Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/action.md Instantiate a GroupButtonAction with a key and label, then set its CSS class and callback function. The callback receives the selected IDs. ```php $action = new GroupButtonAction('key', 'Label'); $action->setClass('btn btn-warning') ->setCallback(function ($ids) { ... }); ``` -------------------------------- ### Get Parent Component Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the parent component of the datagrid, which is typically the Presenter in a Nette Framework application. ```php public function getParentComponent(): Component ``` -------------------------------- ### Datagrid Constructor Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Creates a new Datagrid instance. It accepts an optional parent container and component name. ```php public function __construct(?IContainer $parent = null, ?string $name = null): void ``` -------------------------------- ### Get Current Page - DatagridPaginator Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Retrieves the current page number of the datagrid. The page number is 1-based. ```php public function getPage(): int ``` -------------------------------- ### handleShowAllColumns Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Signal handler automatically invoked by Nette to display all available columns in the datagrid. ```APIDOC ## handleShowAllColumns ### Description Signal handler to show all columns. Invoked automatically by Nette. ### Method ```php public function handleShowAllColumns(): void ``` ``` -------------------------------- ### Get Underlying Data Item Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Returns the original data item associated with the row, which can be an array or an object. ```php public function getItem(): mixed { // ... implementation details } ``` ```php $item = $row->getItem(); if (is_object($item)) { echo $item->getName(); } ``` -------------------------------- ### Get Filter Condition Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Abstract method to be implemented by subclasses to define the data source condition for the filter. ```php abstract public function getCondition(): array ``` -------------------------------- ### Include Datagrid Assets (v6.0.x) Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md Include the necessary CSS and JavaScript files for Datagrid, which now requires Bootstrap 4+. ```html ``` -------------------------------- ### Apply Pagination (Offset and Limit) Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Applies offset and limit to the data for pagination. Returns self for method chaining. ```php public function limit(int $offset, int $limit): self ``` ```php $dataSource->limit(20, 10); // Skip 20, return 10 ``` -------------------------------- ### Trigger DatagridActionCallbackException Source: https://github.com/contributte/datagrid/blob/master/_autodocs/errors.md This example demonstrates an action callback that throws a generic Exception, which will be caught and re-thrown as a DatagridActionCallbackException. ```php $grid->addActionCallback('delete', 'Delete', function ($id) { throw new Exception("Delete failed"); // becomes DatagridActionCallbackException }); ``` -------------------------------- ### Datagrid Constructor Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Initializes a new instance of the Datagrid component. It accepts an optional parent container and a component name. ```APIDOC ## Constructor Creates a new Datagrid instance. ### Signature ```php public function __construct(?IContainer $parent = null, ?string $name = null): void ``` ### Parameters - **parent** (IContainer|null) - Optional - Parent container component. - **name** (string|null) - Optional - Component name. ``` -------------------------------- ### Include Datagrid Assets (v5.x) Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md Include the necessary CSS and JavaScript files for Datagrid with Bootstrap 3 support. ```html ``` -------------------------------- ### Trigger DatagridArrayDataSourceException Source: https://github.com/contributte/datagrid/blob/master/_autodocs/errors.md This example shows how a custom sort callback returning a non-array value can trigger a DatagridArrayDataSourceException. ```php $dataSource = new ArrayDataSource($data); $column->setSortableCallback(function ($data, $sort) { return "invalid"; // Not an array - throws exception }); ``` -------------------------------- ### Get Filter Submit Button Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the configuration object for the submit button of the datagrid's filter form. ```php public function getFilterSubmitButton(): SubmitButton ``` -------------------------------- ### Verify Asset Loading Paths Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md Ensure that the CSS and JavaScript files for the DataGrid are linked with the correct paths in your HTML. This is crucial for the grid to render and function properly. ```html ``` -------------------------------- ### Get Session Section Name Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the session section name used for storing the Datagrid's state. ```php public function getSessionSectionName(): string ``` -------------------------------- ### Get Signal Handler for Sorting Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the currently configured signal handler name used for sorting operations. ```php public function getSortableHandler(): string ``` -------------------------------- ### Find Files Using Old Namespace Source: https://github.com/contributte/datagrid/blob/master/UPGRADE.md Use the grep command to find all files within the 'src/' directory that still reference the old Ublaboo\DataGrid namespace. This helps identify areas needing namespace updates. ```bash # Find all files using old namespace grep -r "Ublaboo\\DataGrid" src/ ``` -------------------------------- ### NoopStateStorage Implementation Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/storage-utilities.md A no-operation state storage that does not persist any data. Use this when stateless behavior is desired, ensuring a fresh grid on every request. ```php $grid->setStateStorage(new NoopStateStorage()); // No state persisted - fresh grid on every request ``` -------------------------------- ### Get Data Items Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Retrieves the actual data items to be displayed in the datagrid. The data can be an array or any Traversable object. ```php public function getData(): iterable ``` ```php $items = $dataSource->getData(); foreach ($items as $item) { echo $item['name']; } ``` -------------------------------- ### FilterSelect Usage Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Illustrates how to implement a dropdown filter with predefined options, allowing users to select from a list of values. Includes configuration for the prompt text. ```APIDOC ## addFilterSelect ### Description Adds a dropdown filter to the datagrid with predefined options. ### Constructor Signature `__construct(Datagrid $grid, string $key, string $name, array $options, ?string $column = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **grid** (Datagrid) - Required - Parent datagrid. - **key** (string) - Required - Filter key. - **name** (string) - Required - Filter label. - **options** (array) - Required - [value => label] pairs. - **column** (string|null) - Optional - Column to filter (defaults to key). ### Example ```php $grid->addFilterSelect('status', 'Status', $options) ->setPrompt('All statuses'); ``` ## setPrompt ### Description Sets the placeholder text that appears in the dropdown when no option is selected. ### Method `setPrompt(string $prompt): self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **prompt** (string) - Required - Prompt text. ### Example ```php $grid->addFilterSelect('status', 'Status', $options) ->setPrompt('All statuses'); ``` ``` -------------------------------- ### Show Inline Add Form Handler Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md The `handleShowInlineAdd` method is an automatic Nette signal handler used to display the inline add form. ```php $grid->handleShowInlineAdd(); ``` -------------------------------- ### PHP Datagrid getItemsDetail Method Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the configuration for the item detail view. Returns the ItemDetail instance or null if not configured. ```php public function getItemsDetail(): ?ItemDetail ``` -------------------------------- ### FilterRange Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Numeric range filter with from/to inputs. Allows setting custom conditions for the start and end of the range. ```APIDOC ## FilterRange Numeric range filter with from/to inputs. ### Methods #### setConditionFrom Set condition for range start (from value). - **condition** (string): Required - Operator (default: >=) #### setConditionTo Set condition for range end (to value). - **condition** (string): Required - Operator (default: <=) ``` -------------------------------- ### getItemsDetail Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieves the configuration for the item detail view. This method allows you to get the current settings for how item details are displayed. ```APIDOC ## getItemsDetail ### Description Get the item detail view configuration. ### Method GET ### Endpoint /datagrid/itemDetail ### Returns #### Success Response (200) - **detail** (ItemDetail|null) - The item detail instance or null ``` -------------------------------- ### Configure Column Summary Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Define column summaries with aggregation functions (sum, avg) and an optional row filter. ```php $grid->setColumnsSummary(['price', 'quantity'], function ($row) { return $row['status'] === 'paid'; }) ->add('price', 'sum') ->add('quantity', 'avg'); ``` -------------------------------- ### Instantiate ApiDataSource Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datasource.md Use this to create a data source that fetches data from an external API. Provide a callable that accepts filter, sort, offset, and limit parameters and returns data. ```php use Contributte\Datagrid\DataSource\ApiDataSource; $dataSource = new ApiDataSource(function ($filter, $sort, $offset, $limit) { // Call external API $response = file_get_contents( 'https://api.example.com/users?filter=' . urlencode(json_encode($filter)) ); return json_decode($response, true); }); $grid->setDataSource($dataSource); ``` -------------------------------- ### handleShowInlineAdd Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Handles the signal to display the inline add form, typically invoked automatically by the Nette framework. ```APIDOC ## handleShowInlineAdd ### Description Signal handler to show inline add form. Invoked automatically by Nette. ### Method ```php public function handleShowInlineAdd(): void ``` ``` -------------------------------- ### Configure Pagination Settings Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Enable or disable pagination, set the default number of items per page, and define the list of available page size options. Use this to control how data is paginated and presented to the user. ```php $grid->setPagination(true) ->setDefaultPerPage(25) ->setItemsPerPageList([10, 25, 50, 100, 'all']); ``` -------------------------------- ### Get Custom Filter Condition Callback Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Use getConditionCallback to retrieve the currently set custom filter condition callback. ```php public function getConditionCallback(): ?callable ``` -------------------------------- ### Get Sort Configuration Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/storage-utilities.md Retrieves the current sort configuration as a column-to-direction mapping. Useful for understanding the active sorting state. ```php public function getSort(): array { // ... implementation details ... } ``` ```php $sort = $sorting->getSort(); // ['name' => 'ASC', 'created_at' => 'DESC'] ``` -------------------------------- ### Configure Item Detail View Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Specify a template for item detail views and configure form elements within the detail view. ```php $grid->setItemsDetail(__DIR__ . '/templates/user-detail.latte', 'id'); $grid->setItemsDetailForm(function (Container $container) { $container->addText('bio', 'Biography:'); }); ``` -------------------------------- ### Data Source Configuration Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Methods for setting and retrieving the data source for the datagrid. ```APIDOC ## setDataSource ### Description Set the data source for the datagrid. Accepts arrays, DataSource objects, or Nette components. ### Method `setDataSource(mixed $source): self` ### Parameters #### Path Parameters - **source** (IDataSource|array|null) - Required - Data source implementation ### Throws - `DatagridWrongDataSourceException` - When source is invalid ### Example ```php $grid->setDataSource($db->query('SELECT * FROM users')); // or $grid->setDataSource($users); // array ``` ``` ```APIDOC ## getDataSource ### Description Get the current data source. ### Method `getDataSource(): IDataSource|array|null` ### Returns - `IDataSource|array|null` - The configured data source ``` -------------------------------- ### Set Date Range Filter Condition From Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Sets the comparison operator for the start date in a date range filter. Defaults to '>='. ```php public function setConditionFrom(string $condition): self ``` ```php $filter->setConditionFrom('>='); ``` -------------------------------- ### Configure Filters & Sorting Source: https://github.com/contributte/datagrid/blob/master/_autodocs/README.md Add a text filter for searching, enable general sorting, and set a default sort order. ```php $grid->addFilterText('search', 'Search', 'name')->setPlaceholder('Enter name...'); $grid->setSortable(true); $grid->setDefaultSort(['created_at' => 'DESC']); ``` -------------------------------- ### Configure Select Filter in Datagrid Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Add a select (dropdown) filter with predefined options and a prompt for the default selection. ```php $grid->addFilterSelect('status', 'Status', [ 'active' => 'Active', 'inactive' => 'Inactive', ]) ->setPrompt('All statuses'); ``` -------------------------------- ### Get Column Count - PHP Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieve the total number of columns currently configured in the datagrid. This can be used for validation or display purposes. ```php public function getColumnsCount(): int ``` ```php echo $grid->getColumnsCount(); // 5 ``` -------------------------------- ### Accessing and Saving Session State Keys Source: https://github.com/contributte/datagrid/blob/master/_autodocs/configuration.md Demonstrates how to retrieve specific session data and save custom data using the Datagrid's storage methods. Useful for persisting grid-specific information. ```php $grid->getStorageData('_grid_hidden_columns'); $grid->saveStorageData('_grid_custom_key', $value); ``` -------------------------------- ### handleShowDefaultColumns Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Signal handler automatically invoked by Nette to display the default set of columns in the datagrid. ```APIDOC ## handleShowDefaultColumns ### Description Signal handler to show default columns. Invoked automatically by Nette. ### Method ```php public function handleShowDefaultColumns(): void ``` ``` -------------------------------- ### Get Column by Key Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Retrieve a specific column instance from the datagrid using its unique key. Throws an exception if the column is not found. ```php public function getColumn(string $key): Column ``` ```php $nameColumn = $grid->getColumn('name'); ``` ``` -------------------------------- ### Get Total Page Count - DatagridPaginator Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Retrieves the total number of pages available in the datagrid. This is useful for displaying pagination controls. ```php public function getPageCount(): int ``` -------------------------------- ### Add Column Summary Calculation Source: https://github.com/contributte/datagrid/blob/master/_autodocs/types.md Configure column summary calculations like sum, average, or count. Specify the column name, the renderer for the summary, and optional replacements. ```php class ColumnsSummary { public function add(string $column, string $renderer, array $replacements = []): self; } ``` -------------------------------- ### Get HTML Placeholder Attribute Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/filter.md Retrieve the current value of the HTML placeholder attribute for a filter. Returns null if no placeholder is set. ```php $grid->getPlaceholder(); ``` -------------------------------- ### Retrieve an Action by Key Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/datagrid.md Use getAction to fetch an existing action, whether it's a single row action or a multi-row action, using its unique key. ```php public function getAction(string $key): Action|MultiAction ``` ```php $action = $grid->getAction('detail'); ``` -------------------------------- ### Get Row CSS Classes Source: https://github.com/contributte/datagrid/blob/master/_autodocs/api-reference/row-export.md Retrieves a string containing all space-separated CSS classes applied to the row's `