Skip to content

Commit

Permalink
Rename all $grid to $datagrid
Browse files Browse the repository at this point in the history
  • Loading branch information
radimvaculik committed May 4, 2024
1 parent 92e4434 commit 10c69c8
Show file tree
Hide file tree
Showing 63 changed files with 276 additions and 276 deletions.
2 changes: 1 addition & 1 deletion .docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Parameters are the same as in ColumnLink:
/**
* $key, $name = '', $href = $key, array $params = NULL
*/
$grid->addAction('edit', 'Edit');
$datagrid->addAction('edit', 'Edit');
```

### Icon
Expand Down
24 changes: 12 additions & 12 deletions .docs/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ There are several column classes and they all have some common behaviour and pro
Let's add a simple text column like we've done before:

```php
$grid->addColumnText('name', 'Name');
$datagrid->addColumnText('name', 'Name');
```

Parameters that the method takes are: `$key, $title, $column = $key`. By default, the column name is the same as the key. There is a key, because you can show more data grid columns that will display only one database table column:

```php
$grid->addColumnText('name', 'Name'); // Equivalent to $grid->addColumnText('name', 'Name', 'name');
$grid->addColumnText('name2', 'Name', 'name');
$grid->addColumnText('name3', 'Name', 'name');
$datagrid->addColumnText('name', 'Name'); // Equivalent to $datagrid->addColumnText('name', 'Name', 'name');
$datagrid->addColumnText('name2', 'Name', 'name');
$datagrid->addColumnText('name3', 'Name', 'name');
```

### Templates

Columns may have it's own template. I will add one more parameter (optional) to the method `::setTemplate()`, just for fun:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setTemplate(__DIR__ . '/templates/name.latte', ['foo' => 'bar']);
```

Expand All @@ -70,7 +70,7 @@ In that template (name.latte), we will have two variables available: `$item` and
We can also modify data outputting via renderer callbacks:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setRenderer(function($item) {
return strtoupper($item->id . ': ' . $item->name);
});
Expand All @@ -79,7 +79,7 @@ $grid->addColumnText('name', 'Name')
But hey, what if I want to replace **just some** rows? No problem, the second optional argument tells me (callback again) whether the datagrid should use your renderer or not. Example:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setRenderer(function($item) {
return strtoupper($item->id . ': ' . $item->name);
}, function($item) {
Expand All @@ -92,7 +92,7 @@ $grid->addColumnText('name', 'Name')
Outputted data could have a simple array replacement instead of renderer callback:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setReplacement([
'John' => 'Doe',
'Hell' => 'o'
Expand All @@ -104,7 +104,7 @@ $grid->addColumnText('name', 'Name')
By default, latte escapes all values from data source. You can disable that:

```php
$grid->addColumnText('link_html', 'Link')
$datagrid->addColumnText('link_html', 'Link')
->setTemplateEscaping(FALSE);
```

Expand All @@ -113,21 +113,21 @@ $grid->addColumnText('link_html', 'Link')
You can set the column as sortable.

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setSortable();
```

When using doctrine as data source, you can output data the object way using dot-notation and property accessor. But when you are using column of related table for sorting, you probably want to use alias for sorting:

```php
$grid->addColumnText('role', 'User role', 'role.name')
$datagrid->addColumnText('role', 'User role', 'role.name')
->setSortable('r.name')
```

### Resetting pagination after sorting

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setSortable()
->setSortableResetPagination();
```
Expand Down
2 changes: 1 addition & 1 deletion .docs/data-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ There are these supported datasources so far:
You can set data source like this:

```php
$grid->setDataSource($this->ndb->table('user')); // NDBT
$datagrid->setDataSource($this->ndb->table('user')); // NDBT
$grid->setDataSource($this->dibi->select('*')->from('user')); // Dibi
$grid->setDataSource([['id' => 1, 'name' => 'John'], ['id' => 2, 'name' => 'Joe']]); // Array
$grid->setDataSource($exampleRepository->createQueryBuilder('er')); // Doctrine query builder
Expand Down
18 changes: 9 additions & 9 deletions .docs/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Table of contents

## ExportCallback

Datagrid allows you to export the data via `$grid->addExportCallback()`. The parameters are:
Datagrid allows you to export the data via `$datagrid->addExportCallback()`. The parameters are:

```php
/**
* $text = Button text
* $callback = your export callback
* $filtered = $should datagrid pass a filtered data to your callback, or all?
*/
$grid->addExportCallback($text, $callback, $filtered = false);
$datagrid->addExportCallback($text, $callback, $filtered = false);
```

You can tell whether to use ajax or not (`->setAjax()`). Or a button title (`->setTitle('Title')`). Or target (`->setTarget('_blank')`).
Expand All @@ -30,9 +30,9 @@ There is already a CSV export implemented (filtered and not filtered):

```php
/**
* Or $grid->addExportCsvFiltered();
* Or $datagrid->addExportCsvFiltered();
*/
$grid->addExportCsv('Csv export (filtered)', 'examples.csv')
$datagrid->addExportCsv('Csv export (filtered)', 'examples.csv')
->setTitle('Csv export (filtered)');
```

Expand All @@ -45,13 +45,13 @@ ExportCsv ignores column template, because i don't like the idea Latte (templati
When you're exporting the data, you can have different columns in export and in the datagrid. Or differently rendered. So there is another method `Contributte\Datagrid\Export\Export::setColumns()`. You can create instances of another columns and pass them in array to this method. These will be rendered in export:

```php
$column_name = new Contributte\Datagrid\Column\ColumnText($grid, 'name', 'name', 'Name');
$column_even = (new Contributte\Datagrid\Column\ColumnText($grid, 'name', 'even', 'Even ID (yes/no)'))
$column_name = new Contributte\Datagrid\Column\ColumnText($datagrid, 'name', 'name', 'Name');
$column_even = (new Contributte\Datagrid\Column\ColumnText($datagrid, 'name', 'even', 'Even ID (yes/no)'))
->setRenderer(function(array $item): string {
return $item['id'] % 2 ? 'No' : 'Yes';
});

$grid->addExportCsv('Csv export', 'examples_all.csv')
$datagrid->addExportCsv('Csv export', 'examples_all.csv')
->setTitle('Csv export')
->setColumns([
$column_name,
Expand All @@ -69,10 +69,10 @@ By default, Datagrid exports data in `utf-8` with semicolon delimiter `;`. This
* $output_encoding = 'utf-8'
* $delimiter = ';'
*/
$grid->addExportCsvFiltered('Csv export (filtered)', 'examples.csv');
$datagrid->addExportCsvFiltered('Csv export (filtered)', 'examples.csv');

/**
* Changed
*/
$grid->addExportCsv( 'Csv export', 'examples_all.csv', 'windows-1250', ',');
$datagrid->addExportCsv( 'Csv export', 'examples_all.csv', 'windows-1250', ',');
```
8 changes: 4 additions & 4 deletions .docs/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ Table of contents
Either you can add filter to existing column by defining column and filter separately:

```php
$grid->addColumnText('name', 'Name');
$grid->addFilterText('name', 'Name');
$datagrid->addColumnText('name', 'Name');
$datagrid->addFilterText('name', 'Name');
```

Or you can add a filter directly to column definition:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setFilterText();
```

Expand All @@ -47,7 +47,7 @@ There are several filter classes and they all have some common behaviour and pro
/**
* $key, $name, $columns
*/
$grid->addFilterText('name', 'Name');
$datagrid->addFilterText('name', 'Name');

/**
* Equivalent
Expand Down
6 changes: 3 additions & 3 deletions .docs/group-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ If you need to do some operations with multiple rows, there are group actions. T
When you want to show just one action button, do simply that:

```php
$grid->addGroupButtonAction('Say hello')->onClick[] = [$this, 'sayHello'];
$datagrid->addGroupButtonAction('Say hello')->onClick[] = [$this, 'sayHello'];
```

### One level

![Group action 1](https://github.com/contributte/datagrid/blob/master/.docs/assets/group_button_action_1.gif?raw=true)

```php
$grid->addGroupAction('Delete examples')->onSelect[] = [$this, 'deleteExamples'];
$grid->addGroupAction('Something else')->onSelect[] = [$this, 'doSomethingElse'];
$datagrid->addGroupAction('Delete examples')->onSelect[] = [$this, 'deleteExamples'];
$datagrid->addGroupAction('Something else')->onSelect[] = [$this, 'doSomethingElse'];
```

This will create one select box (['Delete examples', 'Something else']) and submit button. If you submit that form, your handler will be called. It will be called via ajax.
Expand Down
6 changes: 3 additions & 3 deletions .docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class SimplePresenter extends BasePresenter

public function createComponentSimpleGrid($name)
{
$grid = new Datagrid($this, $name);
$datagrid = new Datagrid($this, $name);

$grid->setDataSource($this->db->select('*')->from('example'));
$grid->addColumnText('name', 'Name');
$datagrid->setDataSource($this->db->select('*')->from('example'));
$datagrid->addColumnText('name', 'Name');
}

}
Expand Down
10 changes: 5 additions & 5 deletions .docs/inline-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Table of contents
Since version `3.3.0` there is a feature "inline adding" available. Up above is a demo where you can try that out. Just hit the "plus" button, fill some inputs and save the container. Example implementation:

```php
$grid->addInlineAdd()
$datagrid->addInlineAdd()
->onControlAdd[] = function(Nette\Forms\Container $container) {
$container->addText('id', '')->setAttribute('readonly');
$container->addText('name', '');
$container->addText('inserted', '');
$container->addText('link', '');
};

$grid->getInlineAdd()->onSubmit[] = function(Nette\Utils\ArrayHash $values): void {
$datagrid->getInlineAdd()->onSubmit[] = function(Nette\Utils\ArrayHash $values): void {
$v = '';

foreach($values as $key => $value) {
Expand All @@ -35,7 +35,7 @@ $grid->getInlineAdd()->onSubmit[] = function(Nette\Utils\ArrayHash $values): voi
As you can see, new item row is rendered at the bottom of the table. You may change that and make datagrid render the new item row on the top:

```php
$grid->addInlineAdd()
$datagrid->addInlineAdd()
->setPositionTop(); // Or take it down again: ::setPositionTop(false)
```

Expand All @@ -44,8 +44,8 @@ $grid->addInlineAdd()
When you use array datasource, there is one limitation. Simply redrawing the grid won't do. You will also have to set the datasource again to refresh the data.

```php
$grid->getInlineAdd()->onSubmit[] = function(ArrayHash $values) use ($grid): void {
$grid->setDatasource($this->model->getDatasource());
$datagrid->getInlineAdd()->onSubmit[] = function(ArrayHash $values) use ($datagrid): void {
$datagrid->setDatasource($this->model->getDatasource());
$this->redrawControl();
};
```
16 changes: 8 additions & 8 deletions .docs/inline-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ As you can see in the example above (or on the homepage), there is column name a
/**
* Example callback
*/
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setSortable()
->setEditableCallback(function($id, $value): void {
echo("Id: $id, new value: $value"); die;
Expand All @@ -29,7 +29,7 @@ $grid->addColumnText('name', 'Name')
/**
* Or you can do that properly
*/
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setEditableCallback([$this, 'columnNameEdited']);
```

Expand All @@ -38,15 +38,15 @@ $grid->addColumnText('name', 'Name')
Small inline edit is not limited to textarea, you can you input of type of your choice (that input will be submitted with either **blur** or **submit** (enter press) event). Example usage:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setEditableCallback(/**...*/)
->setEditableInputType('text', ['class' => 'form-control']);
```

Or you can use a select:

```php
$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setEditableCallback(/**...*/)
->setEditableInputTypeSelect([
0 => 'Offline',
Expand All @@ -63,7 +63,7 @@ $grid->addColumnText('name', 'Name')
As you can see in the demo above, you can edit the link column but actually, only the link text will be edited. That you can achieve by following code:

```php
$grid->addColumnLink('link', 'Link', 'this#demo', 'name', ['id'])
$datagrid->addColumnLink('link', 'Link', 'this#demo', 'name', ['id'])
->setEditableValueCallback(function(Dibi\Row $row): string {
return $row->name;
})
Expand All @@ -87,20 +87,20 @@ Example useage:
/**
* @var Contributte\Datagrid\Datagrid
*/
$grid = new Datagrid($this, $name);
$datagrid = new Datagrid($this, $name);

/**
* Big inline editing
*/
$grid->addInlineEdit()
$datagrid->addInlineEdit()
->onControlAdd[] = function(Nette\Forms\Container $container): void {
$container->addText('id', '');
$container->addText('name', '');
$container->addText('inserted', '');
$container->addText('link', '');
};

$grid->getInlineEdit()->onSetDefaults[] = function(Nette\Forms\Container $container, $item): void {
$datagrid->getInlineEdit()->onSetDefaults[] = function(Nette\Forms\Container $container, $item): void {
$container->setDefaults([
'id' => $item->id,
'name' => $item->name,
Expand Down
14 changes: 7 additions & 7 deletions .docs/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ As you can see in the example below, a `SimpleTranslator` class comes with datag
```php
public function createComponentLocalizationGrid($name): Contributte\Datagrid\Datagrid
{
$grid = new Datagrid($this, $name);
$datagrid = new Datagrid($this, $name);

$grid->setDataSource($this->ndb->table('example'));
$datagrid->setDataSource($this->ndb->table('example'));

$grid->addColumnNumber('id', 'Id')
$datagrid->addColumnNumber('id', 'Id')
->setAlign('start')
->setSortable();

$grid->addColumnText('name', 'Name')
$datagrid->addColumnText('name', 'Name')
->setSortable();

$grid->addColumnDateTime('inserted', 'Inserted');
$datagrid->addColumnDateTime('inserted', 'Inserted');

$translator = new Contributte\Datagrid\Localization\SimpleTranslator([
'contributte_datagrid.no_item_found_reset' => 'Žádné položky nenalezeny. Filtr můžete vynulovat',
Expand All @@ -44,7 +44,7 @@ public function createComponentLocalizationGrid($name): Contributte\Datagrid\Dat
'Inserted' => 'Vloženo'
]);

$grid->setTranslator($translator);
$datagrid->setTranslator($translator);
}
```

Expand All @@ -55,7 +55,7 @@ All filters and their placeholders are translated normally except for `FilterSel
You can change that behaviour:

```php
$grid->addFilterMultiSelect('status', 'Status:', [
$datagrid->addFilterMultiSelect('status', 'Status:', [
0 => 'Offline',
1 => 'Online',
2 => 'Standby'
Expand Down
2 changes: 1 addition & 1 deletion .docs/row.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Table of contents
Now all rows have to provide group action or editing. Or some other of your actions. You can forbid group actions rendering for some items like this:

```php
$grid->allowRowsGroupAction(function(Row $item): bool {
$datagrid->allowRowsGroupAction(function(Row $item): bool {
return $item->id !== 2;
});
```
Expand Down
2 changes: 1 addition & 1 deletion .docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Table of contents
When you set custom datagrid template, you will probably want to extend it. There are some `blocks` defined, so you can extend just some blocks. Presenter:

```php
$grid->setTemplateFile(__DIR__ . '/../../custom_datagrid_template.latte');
$datagrid->setTemplateFile(__DIR__ . '/../../custom_datagrid_template.latte');
```

Template:
Expand Down
Loading

0 comments on commit 10c69c8

Please sign in to comment.