-
-
Notifications
You must be signed in to change notification settings - Fork 24
Refactoring and docs #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Refactoring and docs #237
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
31b80af
Initial docs structure
samdark 69d4c55
Refactor detail view, add guide for it
samdark 5bb279c
Refactor and document list view
samdark 7eca12f
Apply fixes from StyleCI
StyleCIBot 1026ce9
Add docs
samdark abc853e
Add concept
samdark cb1ff07
More on gridview
samdark 1c5be30
phpdoc
samdark f88b4d2
Better naming
samdark eaba11b
fixes
samdark d2715a6
grid docs
samdark bd32257
dpcs
samdark 1bd305c
Apply fixes from StyleCI
StyleCIBot 89f624f
docs
samdark c003a2c
Apply fixes from StyleCI
StyleCIBot 2e14d9d
Complete guide
samdark e76dd22
Merge branch 'master' into 234-docs
samdark 889e62d
Fix merge issues
samdark 0f58103
Apply fixes from StyleCI
StyleCIBot a1078f3
Fixes
samdark 903d42e
phpdoc cleanup
samdark f636f82
Apply fixes from StyleCI
StyleCIBot fdc23e3
Fix psalm
samdark a453b43
Apply fixes from StyleCI
StyleCIBot 32bef46
Apply suggestions from code review
samdark 4aa4d49
Remove unnecessary description
samdark 4e10cc8
Minor fixes
samdark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Yii DataView guide | ||
|
||
- [Concept](concept.md) | ||
- [Detail view](detailview.md) | ||
- [List view](listview.md) | ||
- [Grid view](gridview.md) | ||
- [Pagination and page sizes](pagination.md) | ||
- [URLs](urls.md) | ||
- [Themes](themes.md) | ||
- [Translation](translation.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Concept | ||
|
||
Data view widgets are meant to be used to render items from various data readers | ||
from [yiisoft/data](https://github.com/yiisoft/data) package. | ||
The idea is that data itself and how it's obtained, sorted, paginated, etc. is separated from how it's rendered. | ||
The same data reader could be rendered as a list or a grid or something else, and vice versa, the grid could render | ||
data coming from database, CSV or even REST API. In both cases, a developer changes either only how the data is obtained | ||
or how the data is rendered. | ||
|
||
```mermaid | ||
graph TD; | ||
R[Data Reader] -->|Provides Data| V[Data View]; | ||
|
||
RD[Database] --> R; | ||
RC[CSV] --> R; | ||
RA[REST API] --> R; | ||
|
||
V --> VL[List]; | ||
V --> VG[Grid]; | ||
V --> VO[Other]; | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Detail View | ||
|
||
The `DetailView` widget is designed to display details about a single data item. | ||
It provides a flexible way to render detailed views with customizable attribute layouts. | ||
|
||
## Basic Usage | ||
|
||
The basic usage is the following: | ||
|
||
```php | ||
<?php | ||
use Yiisoft\Yii\DataView\DetailView; | ||
use Yiisoft\Yii\DataView\Field\DataField; | ||
?> | ||
|
||
<?= DetailView::widget() | ||
->data(['id' => 1, 'username' => 'tests 1', 'status' => true]) | ||
->fields( | ||
new DataField('id'), | ||
new DataField('username', label: 'Name of the user'), | ||
new DataField('status'), | ||
) | ||
?> | ||
``` | ||
|
||
In the above the data set via `data()` can be either an object with public fields or an associative array. | ||
What's displayed is defined via fields configurations where each is an instance of `DataField` that may contain | ||
the following: | ||
|
||
- `name` - Property name in the data object or key name in the data array. Optional if `value` is set explicitly. | ||
- `label` - Field label. If not set, `name` is used. | ||
- `labelAttributes` - An array of label's HTML attribute values indexed by attribute names or a function accepting | ||
data and returning the array. | ||
- `labelTag` - Label HTML tag. | ||
- `value` Explicit value. If `null`, the value is obtained from the data by its name. Could be a | ||
function accepting data as an argument and returning the value. | ||
- `valueTag` Value HTML tag. | ||
- `valueAttributes` - An array of value's HTML attribute values indexed by attribute names or a function accepting | ||
data and returning the array. | ||
|
||
## Rendering options | ||
|
||
The widget is fully customizable in terms of how it's rendered. | ||
|
||
### Main widget | ||
|
||
By default, the widget is rendered as | ||
|
||
```html | ||
<div{attributes}> | ||
{header} | ||
<dl{fieldListAttributes}> | ||
{fields} | ||
</dl> | ||
</div> | ||
``` | ||
|
||
The template above could be changed with `template()`. | ||
Attributes for the main widget tag could be set using `attributes()` and attributes for the field list container | ||
could be set with `fieldListAttributes()`. | ||
Header is an extra content displayed and could be set with `header()`. | ||
|
||
`{fields}` placeholder is replaced with the rendered fields. Each field is using a template that defaults to the following: | ||
|
||
```html | ||
<div{attributes}> | ||
{label} | ||
{value} | ||
</div> | ||
``` | ||
|
||
The template could be customized with `fieldTemplate()` and attributes could be set with `fieldAttributes()`. | ||
|
||
|
||
Label is rendered as: | ||
|
||
```html | ||
<{tag}{attributes}>{label}</{tag}> | ||
``` | ||
|
||
The template above could be customized with `labelTemplate()`. | ||
|
||
Tag and its attributes could be set with `labelTag()` or `labelAttributes()` but if `DataField` has corresponding | ||
properties set, they have higher priority. | ||
|
||
If `DataField`'s `label` is set, it is used as is else it falls back to `name`. | ||
|
||
The value is similar. It is rendered as: | ||
|
||
```html | ||
<{tag}{attributes}>{value}</{tag}> | ||
``` | ||
|
||
The template above could be customized with `valueTemplate()`. | ||
|
||
Tag and its attributes could be set with `valueTag()` or `valueAttributes()` but if `DataField` has corresponding | ||
properties set, they have higher priority. | ||
|
||
If `DataField`'s `value` is set, it is used as is else it is getting the value from the data using `name` as either | ||
object property name or array key. | ||
|
||
There are two extra methods, `valueTrue()` and `valueFalse()`. You can use these to define how to display a boolean | ||
value. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.